apps/feeds/middleware.go 486 B raw
1
package main
2
3
import "net/http"
4
5
func (a *App) withCORS(next http.HandlerFunc) http.HandlerFunc {
6
	return func(w http.ResponseWriter, r *http.Request) {
7
		w.Header().Set("Access-Control-Allow-Origin", "*")
8
		w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS")
9
		w.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type")
10
		if r.Method == http.MethodOptions {
11
			w.WriteHeader(http.StatusNoContent)
12
			return
13
		}
14
		next(w, r)
15
	}
16
}