Files
online-backend/internal/handlers/manager/manager.go
GuwandykA ba53b5b5c2 Update Swagger host to port 5005 and harden Gin trusted proxies.
Also add shared nginx config for test.webulgam.com with online-backend path.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-07 18:47:30 +05:00

65 lines
1.7 KiB
Go
Executable File

package handlermanager
import (
"net/http"
"online-back/internal/cards"
"online-back/internal/config"
"online-back/internal/identity"
"online-back/internal/identity/activitylog"
activitylogdb "online-back/internal/identity/activitylog/db"
"online-back/internal/lending"
"online-back/internal/org"
"online-back/pkg/logging"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/jackc/pgx/v4/pgxpool"
)
const adminAPIPrefix = "/api/admin"
func New(cfg *config.Config, client *pgxpool.Pool, logger *logging.Logger) *gin.Engine {
if cfg.IsDebug != nil && !*cfg.IsDebug {
gin.SetMode(gin.ReleaseMode)
}
router := gin.New()
// Trust only loopback and private networks (Docker/K8s/nginx), not all proxies.
_ = router.SetTrustedProxies([]string{
"127.0.0.1",
"::1",
"10.0.0.0/8",
"172.16.0.0/12",
"192.168.0.0/16",
})
router.Use(gin.Recovery(), gin.Logger())
router.Use(cors.New(cors.Config{
AllowOrigins: []string{"*"},
AllowMethods: []string{
http.MethodGet,
http.MethodPost,
http.MethodPut,
http.MethodDelete,
},
AllowHeaders: []string{
"Content-Type",
"Authorization",
"Cache-Control",
},
ExposeHeaders: []string{"Content-Length"},
}))
adminGroup := router.Group(adminAPIPrefix)
adminGroup.Use(activitylog.Record(activitylogdb.NewRepository(client, logger), logger))
// Each bounded context registers its own modules' handlers.
// Add new modules inside the relevant context's router.go rather than here.
identity.Register(adminGroup, client, logger)
org.Register(adminGroup, client, logger)
lending.Register(adminGroup, client, logger)
cards.Register(adminGroup, client, logger)
return router
}