Fix: authentication with stream api
This commit is contained in:
parent
90b7cba68c
commit
f20f06af28
1 changed files with 11 additions and 3 deletions
|
@ -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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue