Monorepo for Tangled tangled.org

Add CORS top level middleware router to knotserver/ #735

merged opened by nekomimi.pet targeting master from [deleted fork]: master

To make it easier to get information about tangled repos, CORS need to be enabled on repo knots otherwise browsers will throw a fit. This change adds those headers. I think maybe the auth routes could do without them as right now it just gives it to all the routes.

Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:ttdrpj45ibqunmfhdsb4zdwq/sh.tangled.repo.pull/3m4ivlx63dd22
+19
Diff #2
+18
knotserver/middleware.go
··· 33 33 ) 34 34 }) 35 35 } 36 + 37 + func (h *Knot) CORS(next http.Handler) http.Handler { 38 + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 39 + // Set CORS headers 40 + w.Header().Set("Access-Control-Allow-Origin", "*") 41 + w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS") 42 + w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization") 43 + w.Header().Set("Access-Control-Max-Age", "86400") 44 + 45 + // Handle preflight requests 46 + if r.Method == "OPTIONS" { 47 + w.WriteHeader(http.StatusOK) 48 + return 49 + } 50 + 51 + next.ServeHTTP(w, r) 52 + }) 53 + }
+1
knotserver/router.go
··· 71 71 func (h *Knot) Router() http.Handler { 72 72 r := chi.NewRouter() 73 73 74 + r.Use(h.CORS) 74 75 r.Use(h.RequestLogger) 75 76 76 77 r.Get("/", func(w http.ResponseWriter, r *http.Request) {

History

3 rounds 4 comments
sign up or login to add to the discussion
2 commits
expand
59a1308e
knotserver: add cors headers as a middleware function
b19de89d
knotserver: have top level router use cors header function
expand 2 comments

renamed commits

Amazing, merging!

pull request successfully merged
2 commits
expand
83963a3d
knotserver/middleware.go: add cors headers as a middleware function
729f7fce
knotserver/router.go: have top level router use cors header function
expand 2 comments

resubmitted to sign off on commits

Awesome, this looks great! Tiny nit about the commits: they can simply be knotserver: โ€ฆ (exclude the filename, we only specify nested directories).

2 commits
expand
88684a67
knotserver/middleware.go: add cors headers as a middleware function
396baab5
knotserver/router.go: have top level router use cors header function
expand 0 comments