forked from ae6rt/decap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cors.go
25 lines (20 loc) · 785 Bytes
/
cors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package main
import (
"net/http"
"github.com/julienschmidt/httprouter"
)
var corsWrapper = func(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
writeCorsHeaders(w)
handler.ServeHTTP(w, r)
})
}
func writeCorsHeaders(w http.ResponseWriter) {
w.Header().Set("Access-Control-Allow-Origin", "http://localhost:9000")
w.Header().Set("Access-Control-Allow-Headers", "DECAP-APP-NAME, DECAP-API-TOKEN, Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With")
w.Header().Set("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE, OPTIONS")
}
// HandleOptions is the httprouter CORS handler.
func HandleOptions(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
writeCorsHeaders(w)
}