Skip to content

Commit 4a0fc00

Browse files
authored
Add CORS support
1 parent d3c2c49 commit 4a0fc00

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

go/server.go

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

1313
"github.com/gin-gonic/gin"
14+
"github.com/gin-contrib/cors"
1415
)
1516

1617
const DBDir = ".local/tmp"
@@ -24,6 +25,17 @@ type HivePathInfo struct {
2425
func main() {
2526
router := gin.Default()
2627

28+
// CORS configuration
29+
config := cors.Config{
30+
AllowOrigins: []string{"*"},
31+
AllowMethods: []string{"GET", "HEAD"},
32+
AllowHeaders: []string{"*"},
33+
ExposeHeaders: []string{},
34+
MaxAge: 5000,
35+
}
36+
37+
router.Use(cors.New(config))
38+
2739
if err := os.MkdirAll(DBDir, os.ModePerm); err != nil {
2840
log.Fatal(err)
2941
}

0 commit comments

Comments
 (0)