初始化
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
// Config 客户端网关配置:无数据库,业务数据全部经反向代理转发到 WMS 后端
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
// Upstream WMS 后端地址
|
||||
Upstream string `yaml:",default=http://127.0.0.1:8890"`
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// New 创建指向 WMS 后端的反向代理。
|
||||
// 请求侧保留 Method/Body/Header(含 Cookie、Authorization);
|
||||
// 响应头默认全量透传(含滑动续签的 X-Renewed-Token,由 WMS 写入)。
|
||||
func New(upstream string) *httputil.ReverseProxy {
|
||||
target, err := url.Parse(upstream)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("Upstream 配置非法: %v", err))
|
||||
}
|
||||
rp := httputil.NewSingleHostReverseProxy(target)
|
||||
origDirector := rp.Director
|
||||
rp.Director = func(req *http.Request) {
|
||||
origDirector(req)
|
||||
req.Host = target.Host
|
||||
}
|
||||
rp.ErrorHandler = func(w http.ResponseWriter, r *http.Request, err error) {
|
||||
http.Error(w, "WMS 服务不可达: "+err.Error(), http.StatusBadGateway)
|
||||
}
|
||||
return rp
|
||||
}
|
||||
Reference in New Issue
Block a user