Browse Source

跨域问题!!!

main
cobb 4 years ago
parent
commit
43d9db8f2b
  1. 6
      main.go

6
main.go

@ -12,6 +12,7 @@ import (
func main() {
r := gin.Default()
r.Use(Cors())
r.POST("/sql", func(c *gin.Context) {
var req struct {
Content string `json:"content"`
@ -32,15 +33,14 @@ func main() {
c.String(http.StatusOK, string(res))
})
r.StaticFS("/", http.FS(web.Static))
r.Use(Cors())
r.Run(":8000")
}
func Cors() gin.HandlerFunc {
return cors.New(cors.Config{
AllowOrigins: []string{"*"},
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "PATCH"},
AllowAllOrigins: true,
AllowCredentials: true,
AllowHeaders: []string{"*"},
MaxAge: time.Second * time.Duration(7200),
})
}
Loading…
Cancel
Save