diff --git a/config.go b/config.go index 4b664f4..fb44cb1 100644 --- a/config.go +++ b/config.go @@ -9,6 +9,7 @@ type config struct { Bind string `json:"bind"` Hostnames []string `json:"hostnames"` TLS bool `json:"tls"` + CORS []string `json:"cors"` } func getConfig() config { diff --git a/config.json.example b/config.json.example index c401236..62dace6 100644 --- a/config.json.example +++ b/config.json.example @@ -1,5 +1,6 @@ { "bind": ":443", "tls": true, - "hostnames": [ "v4.myip.ninja", "v6.myip.ninja" ] + "hostnames": [ "v4.myip.ninja", "v6.myip.ninja" ], + "cors": [ "https://v4.myip.ninja", "https://v6.myip.ninja" ] } \ No newline at end of file diff --git a/main.go b/main.go index a9b212d..55c6e11 100644 --- a/main.go +++ b/main.go @@ -6,12 +6,17 @@ import ( "golang.org/x/crypto/acme/autocert" "github.com/labstack/echo" + "github.com/labstack/echo/middleware" ) func main() { cfg := getConfig() e := echo.New() + e.Use(middleware.CORSWithConfig(middleware.CORSConfig{ + AllowOrigins: cfg.CORS, + })) + e.GET("/", handleRequest) if cfg.TLS { e.AutoTLSManager.HostPolicy = autocert.HostWhitelist(cfg.Hostnames...)