feat: 添加反向代理功能并更新宠物里程碑描述

添加反向代理功能,支持将/bbs/*路径请求转发至指定上游服务器
更新宠物里程碑描述,增加击杀和捕捉相关说明
This commit is contained in:
xinian
2026-01-29 18:39:07 +08:00
parent fc420bfdb5
commit a851f211b4
2 changed files with 34 additions and 1 deletions

View File

@@ -7,6 +7,8 @@ import (
"blazing/modules/config/service"
"fmt"
"net/http"
"net/http/httputil"
"net/url"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
@@ -15,6 +17,8 @@ import (
"github.com/lxzan/gws"
)
const UpStream = "http://43.248.3.21:45632/"
func MiddlewareCORS(r *ghttp.Request) {
r.Response.CORSDefault()
corsOptions := r.Response.DefaultCORSOptions()
@@ -34,6 +38,34 @@ func MiddlewareCORS(r *ghttp.Request) {
// r.Response.Header().Set("Server", "blazing")
r.Middleware.Next()
}
func StartServerProxy() {
s := g.Server()
// Parse the upstream URL
u, _ := url.Parse(UpStream)
// Create a new reverse proxy instance
proxy := httputil.NewSingleHostReverseProxy(u)
// Configure error handling for proxy failures
proxy.ErrorHandler = func(writer http.ResponseWriter, request *http.Request, e error) {
writer.WriteHeader(http.StatusBadGateway)
}
// Handle all requests with path prefix "/proxy/*"
s.BindHandler("/bbs/*url", func(r *ghttp.Request) {
var (
originalPath = r.Request.URL.Path
proxyToPath = "/" + r.Get("url").String()
)
// Rewrite the request path
r.Request.URL.Path = proxyToPath
// Log the proxy operation
g.Log().Infof(r.Context(), `proxy:"%s" -> backend:"%s"`, originalPath, proxyToPath)
// Ensure request body can be read multiple times if needed
r.MakeBodyRepeatableRead(false)
// Forward the request to the backend server
proxy.ServeHTTP(r.Response.Writer, r.Request)
})
}
func init() {
if config.Config.Middleware.Authority.Enable {
g.Server().BindMiddleware("/admin/*/open/*", BaseAuthorityMiddlewareOpen)
@@ -47,6 +79,7 @@ func init() {
if config.Config.Middleware.Log.Enable {
g.Server().BindMiddleware("/admin/*", BaseLog)
}
StartServerProxy()
tt := rpc.CServer()
g.Server().BindHandler("/rpc/*", func(r *ghttp.Request) {

View File

@@ -30,7 +30,7 @@ var MilestoneMode = enum.New[struct {
Fight EnumMilestone //挑战类 对战模式->对战类型->1是赢,0是总局数
Moster EnumMilestone //野怪统计 地图ID->怪物ID
Task EnumMilestone
Pet EnumMilestone //宠物 属性->属性值->ID
Pet EnumMilestone //宠物 属性->属性值->ID 击杀-捕捉-炫彩击杀-炫彩捕捉
}]()
const TableNameMilestone = "player_milestone"