Browse Source

update cors to allow gogame-frontend requests

master
arnaucube 5 years ago
parent
commit
513836c4c7
3 changed files with 12 additions and 4 deletions
  1. +2
    -0
      README.md
  2. +3
    -3
      endpoint/handlers.go
  3. +7
    -1
      endpoint/serve.go

+ 2
- 0
README.md

@ -3,3 +3,5 @@
Nostalgic OGame clone in Go Nostalgic OGame clone in Go
WIP WIP
The frontend is in https://github.com/arnaucube/gogame-frontend

+ 3
- 3
endpoint/handlers.go

@ -27,9 +27,9 @@ func handleInfo(c *gin.Context) {
} }
type RegisterMsg struct { type RegisterMsg struct {
Name string `binding:"required"`
Password string `binding:"required"`
Email string `binding:"required"`
Name string `json:"name" binding:"required"`
Password string `json:"password" binding:"required"`
Email string `json:"email" binding:"required"`
} }
func handleRegister(c *gin.Context) { func handleRegister(c *gin.Context) {

+ 7
- 1
endpoint/serve.go

@ -23,7 +23,13 @@ var gameservice *gamesrv.Service
func newApiService() *gin.Engine { func newApiService() *gin.Engine {
api := gin.Default() api := gin.Default()
api.Use(cors.Default())
api.Use(cors.New(cors.Config{
AllowOrigins: []string{"http://127.0.0.1:8080"},
AllowMethods: []string{"GET", "POST"},
AllowHeaders: []string{"Authorization", "Content-Type"},
AllowCredentials: true,
MaxAge: 12 * time.Hour,
}))
// the jwt middleware // the jwt middleware
authMiddleware, err := jwt.New(&jwt.GinJWTMiddleware{ authMiddleware, err := jwt.New(&jwt.GinJWTMiddleware{

Loading…
Cancel
Save