Remove CORS support

This commit is contained in:
Martin Polden 2016-04-17 14:23:20 +02:00
parent 0d390d0d19
commit 9d8a541caf
3 changed files with 1 additions and 16 deletions

View File

@ -85,7 +85,6 @@ Application Options:
-f, --country-db=FILE Path to GeoIP country database
-c, --city-db=FILE Path to GeoIP city database
-l, --listen=ADDR Listening address (default: :8080)
-x, --cors Allow requests from other domains
-r, --reverse-lookup Perform reverse hostname lookups
-p, --port-lookup Enable port lookup
-t, --template= Path to template (default: index.html)

View File

@ -23,7 +23,6 @@ var USER_AGENT_RE = regexp.MustCompile(
)
type API struct {
CORS bool
Template string
oracle Oracle
ipFromRequest func(*http.Request) (net.IP, error)
@ -190,16 +189,6 @@ func cliMatcher(r *http.Request, rm *mux.RouteMatch) bool {
return USER_AGENT_RE.MatchString(r.UserAgent())
}
func (a *API) requestFilter(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if a.CORS {
w.Header().Set("Access-Control-Allow-Methods", "GET")
w.Header().Set("Access-Control-Allow-Origin", "*")
}
next.ServeHTTP(w, r)
})
}
type appHandler func(http.ResponseWriter, *http.Request) *appError
func (fn appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@ -249,8 +238,7 @@ func (a *API) Handlers() http.Handler {
// Not found handler which returns JSON when appropriate
r.NotFoundHandler = appHandler(a.NotFoundHandler)
// Pass all requests through the request filter
return a.requestFilter(r)
return r
}
func (a *API) ListenAndServe(addr string) error {

View File

@ -14,7 +14,6 @@ func main() {
CountryDBPath string `short:"f" long:"country-db" description:"Path to GeoIP country database" value-name:"FILE" default:""`
CityDBPath string `short:"c" long:"city-db" description:"Path to GeoIP city database" value-name:"FILE" default:""`
Listen string `short:"l" long:"listen" description:"Listening address" value-name:"ADDR" default:":8080"`
CORS bool `short:"x" long:"cors" description:"Allow requests from other domains"`
ReverseLookup bool `short:"r" long:"reverse-lookup" description:"Perform reverse hostname lookups"`
PortLookup bool `short:"p" long:"port-lookup" description:"Enable port lookup"`
Template string `short:"t" long:"template" description:"Path to template" default:"index.html"`
@ -47,7 +46,6 @@ func main() {
}
api := api.New(oracle)
api.CORS = opts.CORS
api.Template = opts.Template
log.Printf("Listening on %s", opts.Listen)