Files
bj_power/bj_power_wms_client/internal/proxy/proxy.go
T
SunYF a2afd2f6dc feat: 五项目业务实现并对接完成
- MES(B): 工单/BOM/备料/工序字典/PLC下发/拧紧/扫码报工/半成品/AGV/追溯逻辑,WMS与海康RCS客户端,看板Redis缓存API(概览/设备/进度/报警/趋势)+SSE
- WMS(C): JWT滑动续签、Excel导入、盘点、内部API、种子数据、独立Postgres配置
- WMS客户端(E): Go网关8891反向代理+内嵌Vue3十页
- 工位终端(D): SQLite本地缓存+模拟拧紧源+内嵌Vue3页面
- Dashboard(A): 看板数据改接MES内部缓存API,SSE实时刷新+vite代理
- 清理各项目球形磨遗留代码,新增部署手册.md
2026-08-27 19:50:57 +08:00

29 lines
786 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
}