mirror of https://github.com/mpolden/echoip
Remove CORS support
This commit is contained in:
parent
0d390d0d19
commit
9d8a541caf
|
@ -85,7 +85,6 @@ Application Options:
|
||||||
-f, --country-db=FILE Path to GeoIP country database
|
-f, --country-db=FILE Path to GeoIP country database
|
||||||
-c, --city-db=FILE Path to GeoIP city database
|
-c, --city-db=FILE Path to GeoIP city database
|
||||||
-l, --listen=ADDR Listening address (default: :8080)
|
-l, --listen=ADDR Listening address (default: :8080)
|
||||||
-x, --cors Allow requests from other domains
|
|
||||||
-r, --reverse-lookup Perform reverse hostname lookups
|
-r, --reverse-lookup Perform reverse hostname lookups
|
||||||
-p, --port-lookup Enable port lookup
|
-p, --port-lookup Enable port lookup
|
||||||
-t, --template= Path to template (default: index.html)
|
-t, --template= Path to template (default: index.html)
|
||||||
|
|
14
api/api.go
14
api/api.go
|
@ -23,7 +23,6 @@ var USER_AGENT_RE = regexp.MustCompile(
|
||||||
)
|
)
|
||||||
|
|
||||||
type API struct {
|
type API struct {
|
||||||
CORS bool
|
|
||||||
Template string
|
Template string
|
||||||
oracle Oracle
|
oracle Oracle
|
||||||
ipFromRequest func(*http.Request) (net.IP, error)
|
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())
|
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
|
type appHandler func(http.ResponseWriter, *http.Request) *appError
|
||||||
|
|
||||||
func (fn appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
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
|
// Not found handler which returns JSON when appropriate
|
||||||
r.NotFoundHandler = appHandler(a.NotFoundHandler)
|
r.NotFoundHandler = appHandler(a.NotFoundHandler)
|
||||||
|
|
||||||
// Pass all requests through the request filter
|
return r
|
||||||
return a.requestFilter(r)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) ListenAndServe(addr string) error {
|
func (a *API) ListenAndServe(addr string) error {
|
||||||
|
|
2
main.go
2
main.go
|
@ -14,7 +14,6 @@ func main() {
|
||||||
CountryDBPath string `short:"f" long:"country-db" description:"Path to GeoIP country database" value-name:"FILE" default:""`
|
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:""`
|
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"`
|
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"`
|
ReverseLookup bool `short:"r" long:"reverse-lookup" description:"Perform reverse hostname lookups"`
|
||||||
PortLookup bool `short:"p" long:"port-lookup" description:"Enable port lookup"`
|
PortLookup bool `short:"p" long:"port-lookup" description:"Enable port lookup"`
|
||||||
Template string `short:"t" long:"template" description:"Path to template" default:"index.html"`
|
Template string `short:"t" long:"template" description:"Path to template" default:"index.html"`
|
||||||
|
@ -47,7 +46,6 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
api := api.New(oracle)
|
api := api.New(oracle)
|
||||||
api.CORS = opts.CORS
|
|
||||||
api.Template = opts.Template
|
api.Template = opts.Template
|
||||||
|
|
||||||
log.Printf("Listening on %s", opts.Listen)
|
log.Printf("Listening on %s", opts.Listen)
|
||||||
|
|
Loading…
Reference in New Issue