Skip to content

Commit

Permalink
add explicit flags for CORS/gzip stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisaaronland committed Mar 23, 2021
1 parent e0fdfcf commit 6285306
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 5 deletions.
2 changes: 2 additions & 0 deletions flags/append.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ func AppendWWWFlags(fs *flag.FlagSet) error {
fs.String(SERVER_URI, "http://localhost:8080", "A valid aaronland/go-http-server URI.")

fs.Bool(ENABLE_WWW, false, "Enable the interactive /debug endpoint to query points and display results.")
fs.Bool(ENABLE_CORS, false, "Enable CORS headers for data-related and API handlers.")
fs.Bool(ENABLE_GZIP, false, "Enable gzip-encoding for data-related and API handlers.")

fs.String(PATH_PREFIX, "", "Prepend this prefix to all assets (but not HTTP handlers). This is mostly for API Gateway integrations.")

Expand Down
2 changes: 2 additions & 0 deletions flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const PATH_PIP string = "path-pip"
const PATH_DATA string = "path-data"

const ENABLE_WWW string = "enable-www"
const ENABLE_CORS string = "enable-cors"
const ENABLE_GZIP string = "enable-gzip"
const ENABLE_TANGRAM string = "enable-tangram"

const NEXTZEN_APIKEY string = "nextzen-apikey"
Expand Down
14 changes: 14 additions & 0 deletions flags/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ func ValidateWWWFlags(fs *flag.FlagSet) error {
return nil
}

bool_flags := []string{
ENABLE_CORS,
ENABLE_GZIP,
}

for _, k := range bool_flags {

_, err := lookup.BoolVar(fs, k)

if err != nil {
return err
}
}

init_lat, err := lookup.Float64Var(fs, INITIAL_LATITUDE)

if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions server/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ func (server_app *HTTPServerApplication) RunWithFlagSet(ctx context.Context, fs
}

enable_www, _ := lookup.BoolVar(fs, www_flags.ENABLE_WWW)
enable_cors, _ := lookup.BoolVar(fs, www_flags.ENABLE_CORS)
enable_gzip, _ := lookup.BoolVar(fs, www_flags.ENABLE_GZIP)

enable_tangram, _ := lookup.BoolVar(fs, www_flags.ENABLE_TANGRAM)

nextzen_apikey, _ := lookup.StringVar(fs, www_flags.NEXTZEN_APIKEY)
Expand Down Expand Up @@ -140,9 +143,6 @@ func (server_app *HTTPServerApplication) RunWithFlagSet(ctx context.Context, fs

mux.Handle(path_ping, ping_handler)

enable_cors := true
enable_gzip := true

cors_origins := []string{"*"}

var cors_wrapper *cors.Cors
Expand Down
4 changes: 3 additions & 1 deletion static/javascript/slippymap.crosshairs.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ slippymap.crosshairs = (function(){
container_el.parentNode.insertBefore(coords, container_el.nextSibling);
}

/*
coords.onclick = function(){
latlon = (latlon) ? false : true;
self.draw_coords(map);
return;
};

*/

var pos = map.getCenter();
var lat = pos['lat'];
var lon = pos['lng'];
Expand Down
1 change: 1 addition & 0 deletions static/javascript/whosonfirst.net.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ whosonfirst.net = (function(){
}

req.open("get", url, true);
// req.setRequestHeader("Accept", "application/jsonx");
req.send();
}

Expand Down
1 change: 0 additions & 1 deletion static/javascript/whosonfirst.spatial.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ whosonfirst.spatial.api = (function(){

req.open("POST", abs_url, true);

req.setRequestHeader("Content-type", "application/json");
// req.setRequestHeader("Accept", "application/geo+json");

var enc_args = JSON.stringify(args);
Expand Down

0 comments on commit 6285306

Please sign in to comment.