chg: cors allowOrigins now configurable
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
|||||||
func CORSMiddleware() gin.HandlerFunc {
|
func CORSMiddleware() gin.HandlerFunc {
|
||||||
logger.Info.Print("Applying CORS")
|
logger.Info.Print("Applying CORS")
|
||||||
return cors.New(cors.Config{
|
return cors.New(cors.Config{
|
||||||
AllowOrigins: []string{config.BaseURL, "http://localhost:8080"}, // Add your frontend URL(s)
|
AllowOrigins: []string{config.Site.AllowOrigins},
|
||||||
AllowMethods: []string{"GET", "POST"}, // "PUT", "PATCH", "DELETE", "OPTIONS"},
|
AllowMethods: []string{"GET", "POST"}, // "PUT", "PATCH", "DELETE", "OPTIONS"},
|
||||||
AllowHeaders: []string{"Origin", "Content-Type", "Accept", "Authorization", "X-Requested-With"},
|
AllowHeaders: []string{"Origin", "Content-Type", "Accept", "Authorization", "X-Requested-With"},
|
||||||
// ExposeHeaders: []string{"Content-Length"},
|
// ExposeHeaders: []string{"Content-Length"},
|
||||||
|
|||||||
@@ -69,10 +69,10 @@ func TestCORSMiddleware(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Allowed origin",
|
name: "Allowed origin",
|
||||||
origin: config.BaseURL,
|
origin: config.Site.AllowOrigins,
|
||||||
expectedStatus: http.StatusOK,
|
expectedStatus: http.StatusOK,
|
||||||
expectedHeaders: map[string]string{
|
expectedHeaders: map[string]string{
|
||||||
"Access-Control-Allow-Origin": config.BaseURL,
|
"Access-Control-Allow-Origin": config.Site.AllowOrigins,
|
||||||
"Content-Type": "text/plain; charset=utf-8",
|
"Content-Type": "text/plain; charset=utf-8",
|
||||||
"Access-Control-Allow-Credentials": "true",
|
"Access-Control-Allow-Credentials": "true",
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user