Skip to content

Commit 6fa1508

Browse files
authored
Add CORS to magic
1 parent 4a0fc00 commit 6fa1508

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

go/server_magic.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"sync"
1212

1313
"github.com/gin-gonic/gin"
14+
"github.com/gin-contrib/cors"
1415
"github.com/joho/godotenv"
1516
_ "github.com/mattn/go-sqlite3"
1617
"github.com/metrico/pasticca/paste"
@@ -49,6 +50,17 @@ func main() {
4950

5051
router := gin.Default()
5152

53+
// CORS configuration
54+
config := cors.Config{
55+
AllowOrigins: []string{"*"},
56+
AllowMethods: []string{"GET", "HEAD"},
57+
AllowHeaders: []string{"*"},
58+
ExposeHeaders: []string{},
59+
MaxAge: 3000,
60+
}
61+
62+
router.Use(cors.New(config))
63+
5264
router.GET("/*path", server.handleRequest)
5365
router.HEAD("/*path", server.handleRequest)
5466
router.POST("/*path", server.handlePostRequest)

0 commit comments

Comments
 (0)