|
@@ -9,11 +9,8 @@ import (
|
|
cache "git.dmitriygnatenko.ru/dima/go-common/cache/ttl_memory_cache"
|
|
cache "git.dmitriygnatenko.ru/dima/go-common/cache/ttl_memory_cache"
|
|
"git.dmitriygnatenko.ru/dima/go-common/db"
|
|
"git.dmitriygnatenko.ru/dima/go-common/db"
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/gofiber/fiber/v2"
|
|
- "github.com/gofiber/fiber/v2/middleware/cors"
|
|
|
|
- "github.com/gofiber/fiber/v2/middleware/recover"
|
|
|
|
"github.com/gofiber/template/html/v2"
|
|
"github.com/gofiber/template/html/v2"
|
|
|
|
|
|
- "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/middleware/language"
|
|
|
|
"git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/repositories"
|
|
"git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/repositories"
|
|
"git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/services/auth"
|
|
"git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/services/auth"
|
|
"git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/services/config"
|
|
"git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/services/config"
|
|
@@ -41,26 +38,15 @@ type ServiceProvider interface {
|
|
func Init(sp ServiceProvider) (*fiber.App, error) {
|
|
func Init(sp ServiceProvider) (*fiber.App, error) {
|
|
fiberApp := fiber.New(getConfig(sp))
|
|
fiberApp := fiber.New(getConfig(sp))
|
|
|
|
|
|
- // Configure web root
|
|
|
|
- fiberApp.Static("/", staticPath)
|
|
|
|
|
|
+ initStatic(fiberApp)
|
|
|
|
|
|
- // Configure CORS middleware
|
|
|
|
- fiberApp.Use(cors.New(getCORSConfig(sp)))
|
|
|
|
|
|
+ initMiddleware(fiberApp, sp)
|
|
|
|
|
|
- // Configure recover middleware
|
|
|
|
- fiberApp.Use(recover.New())
|
|
|
|
|
|
+ initMetrics(fiberApp, sp)
|
|
|
|
|
|
- // Configure language middleware
|
|
|
|
- fiberApp.Use(language.New())
|
|
|
|
|
|
+ initPublicHandlers(fiberApp, sp)
|
|
|
|
|
|
- // Metrics
|
|
|
|
- addMetrics(fiberApp, sp)
|
|
|
|
-
|
|
|
|
- // Public handlers
|
|
|
|
- addPublicHandlers(fiberApp, sp)
|
|
|
|
-
|
|
|
|
- // Protected handlers
|
|
|
|
- addAdminHandlers(fiberApp, sp)
|
|
|
|
|
|
+ initAdminHandlers(fiberApp, sp)
|
|
|
|
|
|
return fiberApp, nil
|
|
return fiberApp, nil
|
|
}
|
|
}
|
|
@@ -74,13 +60,6 @@ func getConfig(sp ServiceProvider) fiber.Config {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func getCORSConfig(sp ServiceProvider) cors.Config {
|
|
|
|
- return cors.Config{
|
|
|
|
- AllowOrigins: sp.ConfigService().CORSAllowOrigins(),
|
|
|
|
- AllowMethods: sp.ConfigService().CORSAllowMethods(),
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
func getViewsEngine(sp ServiceProvider) *html.Engine {
|
|
func getViewsEngine(sp ServiceProvider) *html.Engine {
|
|
engine := html.New(templatesPath, ".html")
|
|
engine := html.New(templatesPath, ".html")
|
|
|
|
|