feat: add static file serving and refactor route registration

This commit is contained in:
2025-12-16 22:40:31 +08:00
parent 55c40c4601
commit 2a12e1c3a9
7 changed files with 41 additions and 21 deletions

View File

@@ -38,7 +38,7 @@ func (ctl *authController) login(ctx fiber.Ctx, form *dto.LoginForm) (*dto.Login
}
if !m.Roles.Contains(consts.RoleSuperAdmin) {
return nil, errorx.Wrap(err).WithMsg("用户名或密码错误")
return nil, errorx.Wrap(errorx.ErrInvalidCredentials).WithMsg("用户名或密码错误")
}
token, err := ctl.jwt.CreateToken(ctl.jwt.CreateClaims(jwt.BaseClaims{

View File

@@ -26,11 +26,13 @@ func Provide(opts ...opt.Option) error {
}
if err := container.Container.Provide(func(
authController *authController,
staticController *staticController,
tenant *tenant,
) (contracts.HttpRoute, error) {
obj := &Routes{
authController: authController,
tenant: tenant,
authController: authController,
staticController: staticController,
tenant: tenant,
}
if err := obj.Prepare(); err != nil {
return nil, err
@@ -40,6 +42,13 @@ func Provide(opts ...opt.Option) error {
}, atom.GroupRoutes); err != nil {
return err
}
if err := container.Container.Provide(func() (*staticController, error) {
obj := &staticController{}
return obj, nil
}); err != nil {
return err
}
if err := container.Container.Provide(func() (*tenant, error) {
obj := &tenant{}

View File

@@ -17,12 +17,13 @@ import (
// Routes implements the HttpRoute contract and provides route registration
// for all controllers in the super module.
//
// @provider contracts.HttpRoute atom.GroupRoutes
// @provider contracts.HttpRoute atom.GroupRoutes
type Routes struct {
log *log.Entry `inject:"false"`
// Controller instances
authController *authController
tenant *tenant
authController *authController
staticController *staticController
tenant *tenant
}
// Prepare initializes the routes provider with logging configuration.
@@ -59,5 +60,7 @@ func (r *Routes) Register(router fiber.Router) {
Body[dto.TenantExpireUpdateForm]("form"),
))
router.Get("/super/*", Func(r.staticController.static))
r.log.Info("Successfully registered all routes")
}

View File

@@ -0,0 +1,20 @@
package super
import (
"github.com/gofiber/fiber/v3"
)
// @provider
type staticController struct{}
// Static
//
// @Tags Super
// @Router /super/*
func (ctl *staticController) static(ctx fiber.Ctx) error {
param := ctx.Params("*")
if param == "" {
param = "index.html"
}
return ctx.SendFile("/home/rogee/Projects/quyun_v2/frontend/superadmin/dist/" + param)
}