refactor: add cors mw for uploads

This commit is contained in:
Derrick Hammer 2024-03-18 13:39:50 -04:00
parent e864bcb098
commit c68dc51732
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 9 additions and 2 deletions

View File

@ -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,