added routes package and serve in server package
This commit is contained in:
1 parent
303b9344f8
commit
547949795f
8 files changed
+74
-77
No files matched your search
@@ -12,9 +12,9 @@ func InitMiddlewares(app *fiber.App) {
|
||||
app.Use(
|
||||
cors.New(
|
||||
cors.Config{
|
||||
AllowOrigins: "https://localhost:3000,https://localhost:43243",
|
||||
AllowOrigins: "*",
|
||||
AllowHeaders: "*",
|
||||
AllowCredentials: true,
|
||||
AllowCredentials: false,
|
||||
},
|
||||
),
|
||||
jwtware.New(
|
||||
|
||||
@@ -3,6 +3,7 @@ package server
|
||||
import (
|
||||
"backend/api"
|
||||
"backend/database"
|
||||
"backend/routes"
|
||||
"backend/utils"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
@@ -13,21 +14,12 @@ func Configure(app *fiber.App) {
|
||||
utils.LoadEnv("wallet.conf")
|
||||
database.InitDatabase()
|
||||
log.SetLevel(log.LevelDebug)
|
||||
|
||||
app.Static("/", "../frontend/build")
|
||||
apiGroup := app.Group("/api")
|
||||
|
||||
apiGroup.Post("/token", api.Login)
|
||||
InitMiddlewares(app)
|
||||
|
||||
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)
|
||||
routes.UsersRoutes(apiGroup)
|
||||
routes.OperationRoutes(apiGroup)
|
||||
routes.CategoryRoutes(apiGroup)
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func Serve(app *fiber.App) {
|
||||
enableTls, err := strconv.ParseBool(os.Getenv("ENABLE_TLS"))
|
||||
if err != nil {
|
||||
log.Fatalf("error read tls configuration, %v", err)
|
||||
}
|
||||
if enableTls {
|
||||
log.Fatal(
|
||||
app.ListenTLS(
|
||||
os.Getenv("HTTP_ADDRESS"),
|
||||
os.Getenv("CERT_FILE"),
|
||||
os.Getenv("KEY_FILE"),
|
||||
),
|
||||
)
|
||||
} else {
|
||||
log.Fatal(
|
||||
app.Listen(os.Getenv("HTTP_ADDRESS")),
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user