Files
wallet/backend/server/configure.go
T
wt 90e5863adc
Build and Test / build-and-test-backend (push) Successful in 31s
Build and Test / build-and-test-frontend (push) Successful in 34s
create and get categories with database for user
2025-08-09 17:32:18 +07:00

67 lines
1.6 KiB
Go

package server
import (
"backend/api"
"backend/database"
"backend/utils"
"os"
jwtware "github.com/gofiber/contrib/jwt"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/log"
"github.com/gofiber/fiber/v2/middleware/cors"
)
func Configure(app *fiber.App) {
utils.LoadEnv("wallet.conf")
database.InitDatabase()
log.SetLevel(log.LevelDebug)
app.Use(cors.New(cors.Config{
AllowOrigins: "http://localhost:3000",
AllowHeaders: "*",
}))
app.Static("/", "../frontend/build")
apiGroup := app.Group("/api")
apiGroup.Post("/token", api.Login)
app.Use(jwtware.New(jwtware.Config{
SigningKey: jwtware.SigningKey{
Key: []byte(os.Getenv("JWT_SECRET_KEY")),
},
// ErrorHandler: func(c *fiber.Ctx, err error) error {
// if err.Error() == "Missing or malformed JWT" {
// return c.Status(
// fiber.StatusBadRequest,
// ).JSON(
// fiber.Map{
// "status": "error",
// "message": "Missing or malformed JWT",
// "data": nil,
// },
// )
// }
// return c.Status(
// fiber.StatusUnauthorized,
// ).JSON(
// fiber.Map{
// "status": "error",
// "message": "Invalid or expired JWT",
// "data": nil,
// "error": err.Error(),
// },
// )
// },
}))
usersGroup := apiGroup.Group("/users")
usersGroup.Get("/", api.GetAllUsers)
usersGroup.Get("/user", api.GetUserData)
operationGroup := apiGroup.Group("/operation")
operationGroup.Get("/", api.GetAllOperation)
categoryGroup := apiGroup.Group("/category")
categoryGroup.Get("/", api.GetAllCategories)
categoryGroup.Post("/", api.CreateCategory)
}