From 541fcff7798c7cb679dbec01de667c5f9380762b Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 25 Jan 2024 18:25:10 -0500 Subject: [PATCH] feat: add cors support --- api/s5.go | 3 ++- go.mod | 1 + go.sum | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/api/s5.go b/api/s5.go index c54ea6f..51a64f2 100644 --- a/api/s5.go +++ b/api/s5.go @@ -5,6 +5,7 @@ import ( "git.lumeweb.com/LumeWeb/portal/api/s5" "git.lumeweb.com/LumeWeb/portal/interfaces" "git.lumeweb.com/LumeWeb/portal/protocols" + "github.com/rs/cors" "go.sia.tech/jape" ) @@ -55,7 +56,7 @@ func getRoutes(h *s5.HttpHandler, portal interfaces.Portal) map[string]jape.Hand "GET /s5/blob/:cid": middleware.ApplyMiddlewares(h.DownloadBlob, middleware.AuthMiddleware(portal)), "GET /s5/metadata/:cid": h.DownloadMetadata, // "GET /s5/download/:cid": middleware.ApplyMiddlewares(h.DownloadFile, middleware.AuthMiddleware(portal)), - "GET /s5/download/:cid": h.DownloadFile, + "GET /s5/download/:cid": middleware.ApplyMiddlewares(h.DownloadFile, cors.Default().Handler), // Pins API "POST /s5/pin/:cid": middleware.ApplyMiddlewares(h.AccountPin, middleware.AuthMiddleware(portal)), diff --git a/go.mod b/go.mod index 9fca608..3bb0fb6 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( github.com/golang-jwt/jwt/v5 v5.2.0 github.com/google/uuid v1.5.0 github.com/julienschmidt/httprouter v1.3.0 + github.com/rs/cors v1.10.1 github.com/samber/lo v1.39.0 github.com/spf13/viper v1.18.2 github.com/tus/tusd/v2 v2.2.3-0.20240125123123-9080d351525d diff --git a/go.sum b/go.sum index fd9d414..040441c 100644 --- a/go.sum +++ b/go.sum @@ -230,6 +230,8 @@ github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzG github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/rs/cors v1.10.1 h1:L0uuZVXIKlI1SShY2nhFfo44TYvDPQ1w4oFkUJNfhyo= +github.com/rs/cors v1.10.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46 h1:GHRpF1pTW19a8tTFrMLUcfWwyC0pnifVo2ClaLq+hP8= github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46/go.mod h1:uAQ5PCi+MFsC7HjREoAz1BU+Mq60+05gifQSsHSDG/8=