mirror of
https://github.com/Dvorinka/ClubLogos.git
synced 2026-06-03 19:42:58 +00:00
push
This commit is contained in:
+16
-5
@@ -4,6 +4,7 @@ import (
|
||||
"database/sql"
|
||||
"log"
|
||||
"os"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -42,17 +43,27 @@ func main() {
|
||||
r.Use(cors.New(cors.Config{
|
||||
AllowOrigins: []string{"*"},
|
||||
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH", "HEAD"},
|
||||
AllowHeaders: []string{"*"},
|
||||
AllowHeaders: []string{"Origin", "Content-Type", "Accept", "Authorization", "X-Requested-With", "Range", "Accept-Language", "Accept-Encoding", "Cache-Control", "Pragma", "If-Modified-Since"},
|
||||
ExposeHeaders: []string{"*"},
|
||||
AllowCredentials: false, // Must be false when using wildcard origins
|
||||
AllowOriginFunc: func(origin string) bool {
|
||||
return true // Allow all origins
|
||||
},
|
||||
AllowCredentials: false,
|
||||
AllowOriginFunc: func(origin string) bool { return true },
|
||||
}))
|
||||
|
||||
// Routes
|
||||
setupRoutes(r)
|
||||
|
||||
// Global preflight handler for any path
|
||||
r.OPTIONS("/*path", func(c *gin.Context) {
|
||||
c.Header("Access-Control-Allow-Origin", "*")
|
||||
c.Header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, PATCH, HEAD")
|
||||
reqHeaders := c.GetHeader("Access-Control-Request-Headers")
|
||||
if reqHeaders == "" {
|
||||
reqHeaders = "Origin, Content-Type, Accept, Authorization, X-Requested-With, Range, Accept-Language, Accept-Encoding, Cache-Control, Pragma, If-Modified-Since"
|
||||
}
|
||||
c.Header("Access-Control-Allow-Headers", reqHeaders)
|
||||
c.Status(http.StatusNoContent)
|
||||
})
|
||||
|
||||
// Start server
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
|
||||
@@ -16,6 +16,15 @@ server {
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|svg|ico|woff|woff2|ttf|eot)$ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public, immutable";
|
||||
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS' always;
|
||||
add_header 'Access-Control-Allow-Headers' '*' always;
|
||||
add_header 'Access-Control-Expose-Headers' '*' always;
|
||||
add_header 'Access-Control-Max-Age' '3600' always;
|
||||
|
||||
if ($request_method = 'OPTIONS') {
|
||||
return 204;
|
||||
}
|
||||
}
|
||||
|
||||
# API proxy to backend
|
||||
@@ -50,6 +59,12 @@ server {
|
||||
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS, PATCH, HEAD' always;
|
||||
add_header 'Access-Control-Allow-Headers' '*' always;
|
||||
add_header 'Access-Control-Expose-Headers' '*' always;
|
||||
add_header 'Access-Control-Max-Age' '3600' always;
|
||||
|
||||
if ($request_method = 'OPTIONS') {
|
||||
return 204;
|
||||
}
|
||||
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
@@ -59,3 +74,4 @@ server {
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user