1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-24 05:17:03 +00:00

add one more project structure recommendation

This commit is contained in:
Gerasimos (Makis) Maropoulos
2021-11-19 14:13:42 +02:00
parent d62392bebc
commit 226a4cb064
15 changed files with 1166 additions and 1 deletions

View File

@@ -0,0 +1,28 @@
package handlers
import "github.com/kataras/iris/v12"
// CORS set ups a cors allow-all.
// We may need to edit it before deployment.
func CORS(allowedOrigin string) iris.Handler { // or "github.com/iris-contrib/middleware/cors"
if allowedOrigin == "" {
allowedOrigin = "*"
}
return func(ctx iris.Context) {
ctx.Header("Access-Control-Allow-Origin", allowedOrigin)
ctx.Header("Access-Control-Allow-Credentials", "true")
// July 2021 Mozzila updated the following document: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy
ctx.Header("Referrer-Policy", "no-referrer-when-downgrade")
ctx.Header("Access-Control-Expose-Headers", "*, Authorization, X-Authorization")
if ctx.Method() == iris.MethodOptions {
ctx.Header("Access-Control-Allow-Methods", "*")
ctx.Header("Access-Control-Allow-Headers", "*")
ctx.Header("Access-Control-Max-Age", "86400")
ctx.StatusCode(iris.StatusNoContent)
return
}
ctx.Next()
}
}