42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"rijig/config"
|
|
"rijig/router"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/gofiber/fiber/v2/middleware/cors"
|
|
)
|
|
|
|
func main() {
|
|
config.SetupConfig()
|
|
app := fiber.New()
|
|
|
|
app.Use(cors.New(cors.Config{
|
|
AllowOrigins: "http://localhost:3000",
|
|
AllowMethods: "GET,POST,PUT,DELETE,OPTIONS",
|
|
AllowHeaders: "Origin, Content-Type, Accept, Authorization, x-api-key",
|
|
AllowCredentials: true,
|
|
}))
|
|
|
|
app.Use(func(c *fiber.Ctx) error {
|
|
c.Set("Access-Control-Allow-Origin", "http://localhost:3000")
|
|
c.Set("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS")
|
|
c.Set("Access-Control-Allow-Headers", "Origin, Content-Type, Accept, Authorization, x-api-key")
|
|
c.Set("Access-Control-Allow-Credentials", "true")
|
|
return c.Next()
|
|
})
|
|
|
|
app.Options("*", func(c *fiber.Ctx) error {
|
|
c.Set("Access-Control-Allow-Origin", "http://localhost:3000")
|
|
c.Set("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS")
|
|
c.Set("Access-Control-Allow-Headers", "Origin, Content-Type, Accept, Authorization, x-api-key")
|
|
c.Set("Access-Control-Allow-Credentials", "true")
|
|
return c.SendStatus(fiber.StatusNoContent)
|
|
})
|
|
|
|
router.SetupRoutes(app)
|
|
|
|
config.StartServer(app)
|
|
}
|