more boilerplate and dev environment
This commit is contained in:
@@ -3,7 +3,10 @@ package main
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@@ -16,6 +19,20 @@ func main() {
|
||||
|
||||
router := gin.Default()
|
||||
|
||||
// Configure CORS. In production, set CORS_ALLOWED_ORIGINS to your public domain.
|
||||
allowedOrigins := []string{"http://localhost:5173"}
|
||||
if envOrigins := os.Getenv("CORS_ALLOWED_ORIGINS"); envOrigins != "" {
|
||||
allowedOrigins = strings.Split(envOrigins, ",")
|
||||
}
|
||||
router.Use(cors.New(cors.Config{
|
||||
AllowOrigins: allowedOrigins,
|
||||
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"},
|
||||
AllowHeaders: []string{"Origin", "Content-Type", "Accept", "Authorization"},
|
||||
ExposeHeaders: []string{"Content-Length"},
|
||||
AllowCredentials: true,
|
||||
MaxAge: 12 * 60 * 60,
|
||||
}))
|
||||
|
||||
router.GET("/ping", func(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"message": "pong",
|
||||
|
||||
Reference in New Issue
Block a user