Skip to content

Commit 9cbb2f4

Browse files
committed
Move cors from macaron to chi and also apply cors to all routers from only /api
1 parent 5a991ec commit 9cbb2f4

File tree

16 files changed

+546
-451
lines changed

16 files changed

+546
-451
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ require (
99
gitea.com/macaron/binding v0.0.0-20190822013154-a5f53841ed2b
1010
gitea.com/macaron/cache v0.0.0-20200924044943-905232fba10b
1111
gitea.com/macaron/captcha v0.0.0-20200825161008-e8597820aaca
12-
gitea.com/macaron/cors v0.0.0-20190826180238-95aec09ea8b4
1312
gitea.com/macaron/csrf v0.0.0-20190822024205-3dc5a4474439
1413
gitea.com/macaron/gzip v0.0.0-20200827120000-efa5e8477cf5
1514
gitea.com/macaron/i18n v0.0.0-20200911004404-4ca3dd0cbd60
@@ -40,6 +39,7 @@ require (
4039
github.com/gliderlabs/ssh v0.3.1
4140
github.com/glycerine/go-unsnap-stream v0.0.0-20190901134440-81cf024a9e0a // indirect
4241
github.com/go-chi/chi v1.5.0
42+
github.com/go-chi/cors v1.1.1
4343
github.com/go-enry/go-enry/v2 v2.5.2
4444
github.com/go-git/go-billy/v5 v5.0.0
4545
github.com/go-git/go-git/v5 v5.2.0

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ gitea.com/macaron/cache v0.0.0-20200924044943-905232fba10b h1:2ZE0JE3bKVBcP1VTrW
5454
gitea.com/macaron/cache v0.0.0-20200924044943-905232fba10b/go.mod h1:W5hKG8T1GBfypp5CRQlgoJU4figIL0jhx02y4XA/NOA=
5555
gitea.com/macaron/captcha v0.0.0-20200825161008-e8597820aaca h1:f5P41nXmXd/YOh8f6098Q0F1Y0QfpyRPSSIkni2XH4Q=
5656
gitea.com/macaron/captcha v0.0.0-20200825161008-e8597820aaca/go.mod h1:J5h3N+1nKTXtU1x4GxexaQKgAz8UiWecNwi/CfX7CtQ=
57-
gitea.com/macaron/cors v0.0.0-20190826180238-95aec09ea8b4 h1:e2rAFDejB0qN8OrY4xP4XSu8/yT6QmWxDZpB3J7r2GU=
58-
gitea.com/macaron/cors v0.0.0-20190826180238-95aec09ea8b4/go.mod h1:rtOK4J20kpMD9XcNsnO5YA843YSTe/MUMbDj/TJ/Q7A=
5957
gitea.com/macaron/csrf v0.0.0-20190822024205-3dc5a4474439 h1:88c34YM29a1GlWLrLBaG/GTT2htDdJz1u3n9+lmPolg=
6058
gitea.com/macaron/csrf v0.0.0-20190822024205-3dc5a4474439/go.mod h1:IsQPHx73HnnqFBYiVHjg87q4XBZyGXXu77xANukvZuk=
6159
gitea.com/macaron/gzip v0.0.0-20200827120000-efa5e8477cf5 h1:6rbhThlqfOb+sSmhrsVFz3bZoAeoloe7TZqyeiPbbWI=
@@ -65,7 +63,6 @@ gitea.com/macaron/i18n v0.0.0-20200911004404-4ca3dd0cbd60/go.mod h1:g5ope1b+iWhB
6563
gitea.com/macaron/inject v0.0.0-20190803172902-8375ba841591/go.mod h1:h6E4kLao1Yko6DOU6QDnQPcuoNzvbZqzj2mtPcEn1aM=
6664
gitea.com/macaron/inject v0.0.0-20190805023432-d4c86e31027a h1:aOKEXkDTnh4euoH0so/THLXeHtQuqHmDPb1xEk6Ehok=
6765
gitea.com/macaron/inject v0.0.0-20190805023432-d4c86e31027a/go.mod h1:h6E4kLao1Yko6DOU6QDnQPcuoNzvbZqzj2mtPcEn1aM=
68-
gitea.com/macaron/macaron v1.3.3-0.20190803174002-53e005ff4827/go.mod h1:/rvxMjIkOq4BM8uPUb+VHuU02ZfAO6R4+wD//tiCiRw=
6966
gitea.com/macaron/macaron v1.3.3-0.20190821202302-9646c0587edb/go.mod h1:0coI+mSPSwbsyAbOuFllVS38awuk9mevhLD52l50Gjs=
7067
gitea.com/macaron/macaron v1.5.0 h1:TvWEcHw1/zaHlo0GTuKEukLh3A99+QsU2mjBrXLXjVQ=
7168
gitea.com/macaron/macaron v1.5.0/go.mod h1:P7hfDbQjcW22lkYkXlxdRIfWOXxH2+K4EogN4Q0UlLY=
@@ -102,7 +99,6 @@ github.com/RoaringBitmap/roaring v0.5.5 h1:naNqvO1mNnghk2UvcsqnzHDBn9DRbCIRy94Gm
10299
github.com/RoaringBitmap/roaring v0.5.5/go.mod h1:puNo5VdzwbaIQxSiDIwfXl4Hnc+fbovcX4IW/dSTtUk=
103100
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
104101
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
105-
github.com/Unknwon/com v0.0.0-20190321035513-0fed4efef755/go.mod h1:voKvFVpXBJxdIPeqjoJuLK+UVcRlo/JLjeToGxPYu68=
106102
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
107103
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
108104
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
@@ -326,6 +322,8 @@ github.com/go-asn1-ber/asn1-ber v1.5.1 h1:pDbRAunXzIUXfx4CB2QJFv5IuPiuoW+sWvr/Us
326322
github.com/go-asn1-ber/asn1-ber v1.5.1/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
327323
github.com/go-chi/chi v1.5.0 h1:2ZcJZozJ+rj6BA0c19ffBUGXEKAT/aOLOtQjD46vBRA=
328324
github.com/go-chi/chi v1.5.0/go.mod h1:REp24E+25iKvxgeTfHmdUoL5x15kBiDBlnIl5bCwe2k=
325+
github.com/go-chi/cors v1.1.1 h1:eHuqxsIw89iXcWnWUN8R72JMibABJTN/4IOYI5WERvw=
326+
github.com/go-chi/cors v1.1.1/go.mod h1:K2Yje0VW/SJzxiyMYu6iPQYa7hMjQX2i/F491VChg1I=
329327
github.com/go-enry/go-enry/v2 v2.5.2 h1:3f3PFAO6JitWkPi1GQ5/m6Xu4gNL1U5soJ8QaYqJ0YQ=
330328
github.com/go-enry/go-enry/v2 v2.5.2/go.mod h1:GVzIiAytiS5uT/QiuakK7TF1u4xDab87Y8V5EJRpsIQ=
331329
github.com/go-enry/go-oniguruma v1.2.1 h1:k8aAMuJfMrqm/56SG2lV9Cfti6tC4x8673aHCcBk+eo=

routers/routes/chi.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"github.com/go-chi/chi"
2828
"github.com/go-chi/chi/middleware"
29+
"github.com/go-chi/cors"
2930
"github.com/prometheus/client_golang/prometheus"
3031
)
3132

@@ -207,6 +208,15 @@ func NewChi() chi.Router {
207208
setupAccessLogger(c)
208209
}
209210

211+
if setting.CORSConfig.Enabled {
212+
c.Use(cors.Handler(cors.Options{
213+
AllowedOrigins: setting.CORSConfig.AllowDomain,
214+
AllowedMethods: setting.CORSConfig.Methods,
215+
AllowCredentials: setting.CORSConfig.AllowCredentials,
216+
MaxAge: int(setting.CORSConfig.MaxAge.Seconds()),
217+
}))
218+
}
219+
210220
c.Use(public.Custom(
211221
&public.Options{
212222
SkipLogging: setting.DisableRouterLog,

routers/routes/macaron.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import (
3636
"gitea.com/macaron/binding"
3737
"gitea.com/macaron/cache"
3838
"gitea.com/macaron/captcha"
39-
"gitea.com/macaron/cors"
4039
"gitea.com/macaron/csrf"
4140
"gitea.com/macaron/gzip"
4241
"gitea.com/macaron/i18n"
@@ -957,16 +956,6 @@ func RegisterMacaronRoutes(m *macaron.Macaron) {
957956
}
958957

959958
var handlers []macaron.Handler
960-
if setting.CORSConfig.Enabled {
961-
handlers = append(handlers, cors.CORS(cors.Options{
962-
Scheme: setting.CORSConfig.Scheme,
963-
AllowDomain: setting.CORSConfig.AllowDomain,
964-
AllowSubdomain: setting.CORSConfig.AllowSubdomain,
965-
Methods: setting.CORSConfig.Methods,
966-
MaxAgeSeconds: int(setting.CORSConfig.MaxAge.Seconds()),
967-
AllowCredentials: setting.CORSConfig.AllowCredentials,
968-
}))
969-
}
970959
handlers = append(handlers, ignSignIn)
971960
m.Group("/api", func() {
972961
apiv1.RegisterRoutes(m)

vendor/gitea.com/macaron/cors/.drone.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

vendor/gitea.com/macaron/cors/.gitignore

Lines changed: 0 additions & 12 deletions
This file was deleted.

vendor/gitea.com/macaron/cors/LICENSE

Lines changed: 0 additions & 201 deletions
This file was deleted.

vendor/gitea.com/macaron/cors/README.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)