fix: issues
This commit is contained in:
Binary file not shown.
@@ -36,3 +36,4 @@ Salt = "LiXi.Y@140202"
|
||||
Type = "local"
|
||||
# Path = "/projects/mp-qvyun/backend/fixtures/processed"
|
||||
Path = "/mnt/yangpingliang/publish/processed"
|
||||
Asset = "/projects/mp-qvyun/frontend/dist"
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"backend/pkg/pg"
|
||||
@@ -14,9 +17,6 @@ import (
|
||||
)
|
||||
|
||||
func (f *Middlewares) WeChatAuthUserInfo(c fiber.Ctx) error {
|
||||
log.WithField("module", "middleware.WeChatAuthUserInfo").Debug("Begin")
|
||||
defer log.WithField("module", "middleware.WeChatAuthUserInfo").Debug("END")
|
||||
|
||||
// 如果请求存在 Authorization 头,则跳过
|
||||
if len(c.GetReqHeaders()["Authorization"]) != 0 {
|
||||
return c.Next()
|
||||
@@ -81,6 +81,13 @@ func (f *Middlewares) WeChatAuthUserInfo(c fiber.Ctx) error {
|
||||
return errors.Wrap(err, "failed to create token")
|
||||
}
|
||||
|
||||
// TODO: send html with jwt token
|
||||
return c.SendString(jwtToken)
|
||||
b, err := os.ReadFile(filepath.Join(f.storagePath.Asset, "index.html"))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to read file")
|
||||
}
|
||||
|
||||
html := strings.ReplaceAll(string(b), "{{JWT}}", jwtToken)
|
||||
|
||||
c.Set("Content-Type", "text/html")
|
||||
return c.SendString(html)
|
||||
}
|
||||
|
||||
@@ -11,9 +11,6 @@ import (
|
||||
)
|
||||
|
||||
func (f *Middlewares) WeChatSilentAuth(c fiber.Ctx) error {
|
||||
log.WithField("module", "middleware.WeChatSilentAuth").Debug("Begin")
|
||||
defer log.WithField("module", "middleware.WeChatSilentAuth").Debug("END")
|
||||
|
||||
// if cookie not exists key "openid", then redirect to the wechat auth page
|
||||
token := c.GetReqHeaders()["Authorization"]
|
||||
if len(token) != 0 {
|
||||
|
||||
@@ -7,9 +7,6 @@ import (
|
||||
|
||||
// 此方法用于微信首次接入时的数据验证
|
||||
func (f *Middlewares) WeChatVerify(c fiber.Ctx) error {
|
||||
log.WithField("module", "middleware.WeChatVerify").Debug("Begin")
|
||||
defer log.WithField("module", "middleware.WeChatVerify").Debug("END")
|
||||
|
||||
// get the query parameters
|
||||
signature := c.Query("signature")
|
||||
timestamp := c.Query("timestamp")
|
||||
|
||||
@@ -2,12 +2,9 @@ package middlewares
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v3"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func (f *Middlewares) DebugMode(c fiber.Ctx) error {
|
||||
log.WithField("module", "middleware.DebugMode").Debug("Begin")
|
||||
defer log.WithField("module", "middleware.DebugMode").Debug("END")
|
||||
// fullURI := c.Request().URI().FullURI()
|
||||
// host := c.BaseURL()
|
||||
// fmt.Println(strings.Split(c.Path(), "/"))
|
||||
|
||||
@@ -8,9 +8,6 @@ import (
|
||||
)
|
||||
|
||||
func (f *Middlewares) ProcessResponse(c fiber.Ctx) error {
|
||||
log.WithField("module", "middleware.ProcessResponse").Debug("Begin")
|
||||
defer log.WithField("module", "middleware.ProcessResponse").Debug("END")
|
||||
|
||||
err := c.Next()
|
||||
if err != nil {
|
||||
log.WithError(err).Error("process response error")
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"backend/modules/users"
|
||||
"backend/providers/app"
|
||||
"backend/providers/jwt"
|
||||
"backend/providers/storage"
|
||||
"backend/providers/wechat"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -11,11 +12,12 @@ import (
|
||||
|
||||
// @provider
|
||||
type Middlewares struct {
|
||||
app *app.Config
|
||||
client *wechat.Client
|
||||
userSvc *users.Service
|
||||
jwt *jwt.JWT
|
||||
log *log.Entry `inject:"false"`
|
||||
app *app.Config
|
||||
storagePath *storage.Config
|
||||
client *wechat.Client
|
||||
userSvc *users.Service
|
||||
jwt *jwt.JWT
|
||||
log *log.Entry `inject:"false"`
|
||||
}
|
||||
|
||||
func (f *Middlewares) Prepare() error {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"backend/modules/medias"
|
||||
"backend/modules/middlewares"
|
||||
"backend/modules/users"
|
||||
@@ -15,7 +17,6 @@ import (
|
||||
"git.ipao.vip/rogeecn/atom"
|
||||
"git.ipao.vip/rogeecn/atom/container"
|
||||
"git.ipao.vip/rogeecn/atom/contracts"
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/gofiber/fiber/v3/middleware/favicon"
|
||||
"github.com/gofiber/fiber/v3/middleware/static"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -70,21 +71,19 @@ func Serve(cmd *cobra.Command, args []string) error {
|
||||
|
||||
engine.Use(mid.DebugMode)
|
||||
engine.Use(mid.ProcessResponse)
|
||||
engine.Use(mid.WeChatVerify)
|
||||
|
||||
wechatGroup := engine.Group("/t")
|
||||
wechatGroup.Use(mid.WeChatVerify)
|
||||
wechatGroup.Use(mid.WeChatAuthUserInfo)
|
||||
wechatGroup.Use(mid.WeChatSilentAuth)
|
||||
wechatGroup.Get("*", func(c fiber.Ctx) error {
|
||||
return c.SendString("ok")
|
||||
})
|
||||
engine.Use("/t+", mid.WeChatAuthUserInfo, mid.WeChatSilentAuth)
|
||||
|
||||
http.Service.Engine.Use(favicon.New(favicon.Config{
|
||||
Data: []byte{},
|
||||
}))
|
||||
|
||||
http.Service.Engine.Use("/static", static.New(http.Storage.Path, static.Config{
|
||||
Browse: true,
|
||||
Browse: http.App.IsDevMode(),
|
||||
}))
|
||||
http.Service.Engine.Use("/assets", static.New(filepath.Join(http.Storage.Asset, "assets"), static.Config{
|
||||
Browse: http.App.IsDevMode(),
|
||||
}))
|
||||
|
||||
group := http.Service.Engine.Group("/v1")
|
||||
|
||||
Reference in New Issue
Block a user