feat: add cors middleware

This commit is contained in:
Muyao CHEN
2024-10-03 20:53:56 +02:00
parent 7886788c35
commit ffaec01809
3 changed files with 13 additions and 0 deletions

View File

@ -27,7 +27,9 @@ import (
"net/http"
"git.vinchent.xyz/vinchent/howmuch/internal/pkg/log"
"git.vinchent.xyz/vinchent/howmuch/internal/pkg/middleware"
"git.vinchent.xyz/vinchent/howmuch/pkg/version/verflag"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@ -96,6 +98,14 @@ func run() error {
r := gin.Default()
// Middlewares
corsCfg := cors.DefaultConfig()
corsCfg.AllowAllOrigins = true
corsCfg.AllowHeaders = append(corsCfg.AllowHeaders, "Authorization", "Accept", "X-CSRF-Token")
r.Use(cors.New(corsCfg))
r.Use(middleware.RequestID())
r.GET("/", func(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{
"message": "how much?",