feat: add cors middleware
This commit is contained in:
@ -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?",
|
||||
|
Reference in New Issue
Block a user