mirror of
https://github.com/matrix-org/sliding-sync.git
synced 2025-03-10 13:37:11 +00:00
Support CORS on /sync
This commit is contained in:
parent
398fc1ec6c
commit
d8bc5b3aa7
8
v3.go
8
v3.go
@ -32,10 +32,10 @@ func (s *server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
func allowCORS(next http.Handler) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, req *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
|
||||
w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization")
|
||||
if req.Method == "OPTIONS" {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
|
||||
w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization")
|
||||
w.WriteHeader(200)
|
||||
return
|
||||
}
|
||||
@ -47,7 +47,7 @@ func allowCORS(next http.Handler) http.HandlerFunc {
|
||||
func RunSyncV3Server(h http.Handler, bindAddr string) {
|
||||
// HTTP path routing
|
||||
r := mux.NewRouter()
|
||||
r.Handle("/_matrix/client/v3/sync", h)
|
||||
r.Handle("/_matrix/client/v3/sync", allowCORS(h))
|
||||
r.PathPrefix("/client/").HandlerFunc(
|
||||
allowCORS(
|
||||
http.StripPrefix("/client/", http.FileServer(http.Dir("./client"))),
|
||||
|
Loading…
x
Reference in New Issue
Block a user