MCPcopy
hub / github.com/shadow1ng/fscan / corsMiddleware

Function corsMiddleware

web/server.go:112–125  ·  view source on GitHub ↗

corsMiddleware 添加CORS头(开发时需要)

(next http.Handler)

Source from the content-addressed store, hash-verified

110
111// corsMiddleware 添加CORS头(开发时需要)
112func corsMiddleware(next http.Handler) http.Handler {
113 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
114 w.Header().Set("Access-Control-Allow-Origin", "*")
115 w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
116 w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
117
118 if r.Method == "OPTIONS" {
119 w.WriteHeader(http.StatusOK)
120 return
121 }
122
123 next.ServeHTTP(w, r)
124 })
125}

Callers 1

StartServerFunction · 0.85

Calls 1

WriteHeaderMethod · 0.65

Tested by

no test coverage detected