From c68dc517324cf388889b5112f990cf2b336fbf6f Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 18 Mar 2024 13:39:50 -0400 Subject: [PATCH] refactor: add cors mw for uploads --- api/s5/s5.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/api/s5/s5.go b/api/s5/s5.go index 01799b0..809073e 100644 --- a/api/s5/s5.go +++ b/api/s5/s5.go @@ -179,6 +179,13 @@ func (s *S5API) Routes() (*httprouter.Router, error) { debugCors := cors.Default() + uploadCors := cors.New(cors.Options{ + AllowOriginFunc: func(origin string) bool { + return true + }, + AllowedMethods: []string{"*"}, + }) + routes := map[string]jape.Handler{ // Account API "GET /s5/account/register": s.accountRegisterChallenge, @@ -191,8 +198,8 @@ func (s *S5API) Routes() (*httprouter.Router, error) { "GET /s5/account/pins": middleware.ApplyMiddlewares(s.accountPins, authMw), // Upload API - "POST /s5/upload": middleware.ApplyMiddlewares(s.smallFileUpload, authMw), - "POST /s5/upload/directory": middleware.ApplyMiddlewares(s.directoryUpload, authMw), + "POST /s5/upload": middleware.ApplyMiddlewares(s.smallFileUpload, uploadCors.Handler, authMw), + "POST /s5/upload/directory": middleware.ApplyMiddlewares(s.directoryUpload, uploadCors.Handler, authMw), // Tus API "POST /s5/upload/tus": tusHandler,