Add: cors for external controller

This commit is contained in:
Dreamacro
2018-07-19 09:31:53 +08:00
parent d540a0d29f
commit 7357d2d0c2
3 changed files with 26 additions and 6 deletions

View File

@ -8,6 +8,7 @@ import (
T "github.com/Dreamacro/clash/tunnel"
"github.com/go-chi/chi"
"github.com/go-chi/cors"
"github.com/go-chi/render"
log "github.com/sirupsen/logrus"
)
@ -20,6 +21,15 @@ type Traffic struct {
func NewHub(addr string) {
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("/logs", getLogs)
r.Mount("/configs", configRouter())