Update backend/middleware/middleware.go
Browse files
backend/middleware/middleware.go
CHANGED
|
@@ -2,6 +2,7 @@ package middleware
|
|
| 2 |
|
| 3 |
import (
|
| 4 |
"log"
|
|
|
|
| 5 |
"time"
|
| 6 |
|
| 7 |
"github.com/gofiber/fiber/v2"
|
|
@@ -12,10 +13,19 @@ import (
|
|
| 12 |
func SetupMiddleware(app *fiber.App) {
|
| 13 |
app.Use(recover.New())
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
app.Use(cors.New(cors.Config{
|
| 16 |
-
AllowOrigins:
|
| 17 |
AllowMethods: "GET,POST,OPTIONS",
|
| 18 |
-
AllowHeaders: "Content-Type,Authorization",
|
|
|
|
| 19 |
}))
|
| 20 |
|
| 21 |
app.Use(requestLogger)
|
|
|
|
| 2 |
|
| 3 |
import (
|
| 4 |
"log"
|
| 5 |
+
"os"
|
| 6 |
"time"
|
| 7 |
|
| 8 |
"github.com/gofiber/fiber/v2"
|
|
|
|
| 13 |
func SetupMiddleware(app *fiber.App) {
|
| 14 |
app.Use(recover.New())
|
| 15 |
|
| 16 |
+
// Read allowed origins from env — set ALLOWED_ORIGINS on HuggingFace to your Render frontend URL
|
| 17 |
+
// e.g. ALLOWED_ORIGINS=https://creepurl.onrender.com
|
| 18 |
+
// Defaults to * (all origins) so it works out of the box
|
| 19 |
+
allowedOrigins := os.Getenv("ALLOWED_ORIGINS")
|
| 20 |
+
if allowedOrigins == "" {
|
| 21 |
+
allowedOrigins = "*"
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
app.Use(cors.New(cors.Config{
|
| 25 |
+
AllowOrigins: allowedOrigins,
|
| 26 |
AllowMethods: "GET,POST,OPTIONS",
|
| 27 |
+
AllowHeaders: "Content-Type,Authorization,Accept",
|
| 28 |
+
MaxAge: 300,
|
| 29 |
}))
|
| 30 |
|
| 31 |
app.Use(requestLogger)
|