Added CSRF middleware
This commit is contained in:
parent
11f84b9755
commit
21f3a3d000
@ -10,10 +10,10 @@ import (
|
|||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/fiber/v2/middleware/cors"
|
"github.com/gofiber/fiber/v2/middleware/cors"
|
||||||
|
"github.com/gofiber/fiber/v2/middleware/csrf"
|
||||||
"github.com/gofiber/fiber/v2/middleware/logger"
|
"github.com/gofiber/fiber/v2/middleware/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*Init : set the port,cors,api and then serve the api*/
|
|
||||||
func Init() {
|
func Init() {
|
||||||
app := fiber.New(fiber.Config{
|
app := fiber.New(fiber.Config{
|
||||||
ErrorHandler: func(ctx *fiber.Ctx, err error) error {
|
ErrorHandler: func(ctx *fiber.Ctx, err error) error {
|
||||||
@ -33,6 +33,10 @@ func Init() {
|
|||||||
AllowCredentials: true,
|
AllowCredentials: true,
|
||||||
}))
|
}))
|
||||||
app.Use(logger.New())
|
app.Use(logger.New())
|
||||||
|
app.Use(csrf.New(csrf.Config{
|
||||||
|
CookieHTTPOnly: true,
|
||||||
|
CookieSameSite: "strict",
|
||||||
|
}))
|
||||||
|
|
||||||
api := app.Group("/api")
|
api := app.Group("/api")
|
||||||
v1 := api.Group("/v1")
|
v1 := api.Group("/v1")
|
||||||
@ -46,7 +50,7 @@ func Init() {
|
|||||||
return c.SendString("This is a protected route!")
|
return c.SendString("This is a protected route!")
|
||||||
})
|
})
|
||||||
|
|
||||||
// Serve SPA
|
// Serve React frontend
|
||||||
app.Static("/", "./dist")
|
app.Static("/", "./dist")
|
||||||
app.Get("/*", func(ctx *fiber.Ctx) error {
|
app.Get("/*", func(ctx *fiber.Ctx) error {
|
||||||
return ctx.SendFile("./dist/index.html")
|
return ctx.SendFile("./dist/index.html")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user