Migrated from React to NextJS

This commit is contained in:
2022-10-14 13:58:57 +02:00
parent b2a16e5181
commit b4ff0c8f77
72 changed files with 1557 additions and 1686 deletions

View File

@ -1,20 +1,28 @@
package app
import (
"fmt"
"log"
"os"
"twitch-clone/pkg/auth"
"twitch-clone/pkg/database"
"twitch-clone/pkg/handler"
"twitch-clone/pkg/middleware"
"twitch-clone/pkg/models"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/csrf"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/joho/godotenv"
)
func Init() {
err := godotenv.Load()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
app := fiber.New(fiber.Config{
ErrorHandler: func(ctx *fiber.Ctx, err error) error {
code := fiber.StatusInternalServerError
@ -26,6 +34,7 @@ func Init() {
},
})
database.ConnectDb()
auth.CreateClient()
app.Use(cors.New(cors.Config{
AllowOrigins: "*",
@ -33,19 +42,12 @@ func Init() {
AllowCredentials: true,
}))
app.Use(logger.New())
app.Use(csrf.New(csrf.Config{
CookieHTTPOnly: true,
CookieSameSite: "strict",
}))
api := app.Group("/api")
v1 := api.Group("/v1")
auth := v1.Group("/auth")
auth.Post("login", handler.Login)
auth.Post("register", handler.Register)
test := v1.Group("/test", middleware.CheckToken)
test := v1.Group("/test")
test.Use(middleware.CheckSession)
test.Get("/", func(c *fiber.Ctx) error {
return c.SendString("This is a protected route!")
})
@ -56,7 +58,7 @@ func Init() {
return ctx.SendFile("./dist/index.html")
})
err := app.Listen(":5000")
err = app.Listen(":5000")
if err != nil {
log.Fatal(err.Error())
}