Fix: authentication with stream api

This commit is contained in:
gVisor bot 2018-12-29 14:11:54 +08:00
parent 90b7cba68c
commit f20f06af28

View file

@ -42,16 +42,20 @@ func Start(addr string, secret string) {
cors := cors.New(cors.Options{ cors := cors.New(cors.Options{
AllowedOrigins: []string{"*"}, AllowedOrigins: []string{"*"},
AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"}, AllowedMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE"},
AllowedHeaders: []string{"Content-Type", "Authorization"}, AllowedHeaders: []string{"Content-Type", "Authorization"},
MaxAge: 300, MaxAge: 300,
}) })
root := chi.NewRouter().With(jsonContentType)
root.Get("/traffic", traffic)
root.Get("/logs", getLogs)
r.Get("/", hello)
r.Group(func(r chi.Router) { r.Group(func(r chi.Router) {
r.Use(cors.Handler, authentication) r.Use(cors.Handler, authentication)
r.With(jsonContentType).Get("/traffic", traffic) r.Mount("/", root)
r.With(jsonContentType).Get("/logs", getLogs)
r.Mount("/configs", configRouter()) r.Mount("/configs", configRouter())
r.Mount("/proxies", proxyRouter()) r.Mount("/proxies", proxyRouter())
r.Mount("/rules", ruleRouter()) r.Mount("/rules", ruleRouter())
@ -104,6 +108,10 @@ func authentication(next http.Handler) http.Handler {
return http.HandlerFunc(fn) return http.HandlerFunc(fn)
} }
func hello(w http.ResponseWriter, r *http.Request) {
render.JSON(w, r, render.M{"hello": "clash"})
}
func traffic(w http.ResponseWriter, r *http.Request) { func traffic(w http.ResponseWriter, r *http.Request) {
render.Status(r, http.StatusOK) render.Status(r, http.StatusOK)