Add: cors for external controller

This commit is contained in:
gVisor bot 2018-07-19 09:31:53 +08:00
parent 102d74281f
commit 18696e7715
3 changed files with 26 additions and 6 deletions

16
Gopkg.lock generated
View file

@ -19,6 +19,12 @@
revision = "e83ac2304db3c50cf03d96a2fcd39009d458bc35" revision = "e83ac2304db3c50cf03d96a2fcd39009d458bc35"
version = "v3.3.2" version = "v3.3.2"
[[projects]]
name = "github.com/go-chi/cors"
packages = ["."]
revision = "dba6525398619dead495962a916728e7ee2ca322"
version = "v1.0.0"
[[projects]] [[projects]]
name = "github.com/go-chi/render" name = "github.com/go-chi/render"
packages = ["."] packages = ["."]
@ -65,7 +71,7 @@
"poly1305", "poly1305",
"ssh/terminal" "ssh/terminal"
] ]
revision = "027cca12c2d63e3d62b670d901e8a2c95854feec" revision = "a2144134853fc9a27a7b1e3eb4f19f1a76df13c9"
[[projects]] [[projects]]
branch = "master" branch = "master"
@ -75,7 +81,7 @@
"unix", "unix",
"windows" "windows"
] ]
revision = "6c888cc515d3ed83fc103cf1d84468aad274b0a7" revision = "ac767d655b305d4e9612f5f6e33120b9176c4ad4"
[[projects]] [[projects]]
name = "gopkg.in/eapache/channels.v1" name = "gopkg.in/eapache/channels.v1"
@ -86,12 +92,12 @@
[[projects]] [[projects]]
name = "gopkg.in/ini.v1" name = "gopkg.in/ini.v1"
packages = ["."] packages = ["."]
revision = "06f5f3d67269ccec1fe5fe4134ba6e982984f7f5" revision = "358ee7663966325963d4e8b2e1fbd570c5195153"
version = "v1.37.0" version = "v1.38.1"
[solve-meta] [solve-meta]
analyzer-name = "dep" analyzer-name = "dep"
analyzer-version = 1 analyzer-version = 1
inputs-digest = "c3c901e4e393a2df9e421924d3a4d85ec73642e36dcbc1ddca5fc13159220e86" inputs-digest = "0ccb06b3617c87e75bd650f92adc99e55b93070e0b2a0bc71634270226e125fc"
solver-name = "gps-cdcl" solver-name = "gps-cdcl"
solver-version = 1 solver-version = 1

View file

@ -29,6 +29,10 @@
name = "github.com/go-chi/chi" name = "github.com/go-chi/chi"
version = "3.3.2" version = "3.3.2"
[[constraint]]
name = "github.com/go-chi/cors"
version = "1.0.0"
[[constraint]] [[constraint]]
name = "github.com/go-chi/render" name = "github.com/go-chi/render"
version = "1.0.1" version = "1.0.1"
@ -51,7 +55,7 @@
[[constraint]] [[constraint]]
name = "gopkg.in/ini.v1" name = "gopkg.in/ini.v1"
version = "1.37.0" version = "1.38.1"
[prune] [prune]
go-tests = true go-tests = true

View file

@ -8,6 +8,7 @@ import (
T "github.com/Dreamacro/clash/tunnel" T "github.com/Dreamacro/clash/tunnel"
"github.com/go-chi/chi" "github.com/go-chi/chi"
"github.com/go-chi/cors"
"github.com/go-chi/render" "github.com/go-chi/render"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@ -20,6 +21,15 @@ type Traffic struct {
func NewHub(addr string) { func NewHub(addr string) {
r := chi.NewRouter() r := chi.NewRouter()
cors := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowedHeaders: []string{"Content-Type"},
MaxAge: 300,
})
r.Use(cors.Handler)
r.Get("/traffic", traffic) r.Get("/traffic", traffic)
r.Get("/logs", getLogs) r.Get("/logs", getLogs)
r.Mount("/configs", configRouter()) r.Mount("/configs", configRouter())