fix: issues

This commit is contained in:
yanghao05
2025-04-25 21:19:03 +08:00
parent b35abb2090
commit 5bc3ae468d
15 changed files with 129 additions and 64 deletions

View File

@@ -2,8 +2,8 @@ package http
import (
"context"
"path/filepath"
"quyun/app/errorx"
appHttp "quyun/app/http"
"quyun/app/jobs"
"quyun/app/middlewares"
@@ -25,7 +25,9 @@ import (
"go.ipao.vip/atom/container"
"go.ipao.vip/atom/contracts"
"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/middleware/favicon"
"github.com/rogeecn/fabfile"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"go.uber.org/dig"
@@ -84,22 +86,54 @@ func Serve(cmd *cobra.Command, args []string) error {
svc.Http.Engine.Get("/swagger/*", swagger.HandlerDefault)
}
svc.Http.Engine.Use(errorx.Middleware)
// svc.Http.Engine.Use(errorx.Middleware)
svc.Http.Engine.Use(svc.Middlewares.DebugMode)
svc.Http.Engine.Use(favicon.New(favicon.Config{
Data: []byte{},
}))
group := svc.Http.Engine.Group("")
group := svc.Http.Engine.
Group("v1").
Use(
svc.Middlewares.WechatMpVerify,
svc.Middlewares.Auth,
svc.Middlewares.AuthAdmin,
)
for _, route := range svc.Routes {
if route.Name() == "admin" {
route.Register(group.Use(svc.Middlewares.AuthAdmin))
route.Register(group)
continue
}
route.Register(group.Use(svc.Middlewares.Auth))
route.Register(group)
}
// statics
svc.Http.Engine.Get("/admin*", func(ctx fiber.Ctx) error {
f := ctx.Params("*")
if f == "/" {
f = "index.html"
}
file, err := fabfile.Find(filepath.Join("frontend/admin/dist", f))
if err != nil {
return ctx.SendStatus(fiber.StatusNotFound)
}
return ctx.SendFile(file)
})
svc.Http.Engine.Get("*", func(ctx fiber.Ctx) error {
f := ctx.Params("*")
if f == "/" || f == "" {
f = "index.html"
}
file, err := fabfile.Find(filepath.Join("frontend/wechat/dist", f))
if err != nil {
return ctx.SendStatus(fiber.StatusNotFound)
}
return ctx.SendFile(file)
})
// job
if err := svc.Job.Start(ctx); err != nil {
log.WithError(err).Error("job start failed")
return err