fix(web): SSE 活动流默认同源,修复反代部署连不上 :8787
sseUrl() 原先无条件把 SSE 地址拼成 ${hostname}:8787,连生产静态导出
也带这个硬编码。反代到 443 的部署里页面从 https://域名/ 加载,SSE 却被
指向 https://域名:8787/...,而 8787 未对公网开放,导致活动流连不上、反复重连。
改为用 NODE_ENV 区分:生产默认同源(相对路径),仅 next dev 保留 :8787
以绕过 Next.js /api 反代对 SSE 的缓冲。NEXT_PUBLIC_SSE_BASE 覆盖口保留。
验证:NEXT_EXPORT=1 next build 后生产包里 :8787 分支已被 tree-shake。
补充 README 反向代理部署文档(同源说明 + nginx 关缓冲配置)。
Closes #169
This commit is contained in:
1 parent
160fe13c24
commit
e2c8a23a98
2 files changed
+48
-9
No files matched your search
@@ -222,6 +222,35 @@ CGO_ENABLED=0 go build -tags embedui -o artex ./cmd/artex
|
||||
|
||||
**常用参数**:`./start.sh -addr :8787 -proxy :8788`(`-addr` 前端+API,`-proxy` 流量录制代理)。启动脚本会把参数原样透传给 `artex`。
|
||||
|
||||
### 反向代理部署(HTTPS / 只开放 443)
|
||||
|
||||
前端和 API/SSE 都由同一个后端端口(默认 `:8787`)提供,实时活动流默认走**同源**地址,因此**无需配置 `NEXT_PUBLIC_SSE_BASE`**,公网只开放 443、把 8787 留在内网即可。
|
||||
|
||||
SSE 是长连接 + 持续推送,反代**必须关闭缓冲**,否则浏览器能连上却收不到事件(表现为活动流一直转圈)。Nginx 示例:
|
||||
|
||||
```nginx
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name your.domain.com;
|
||||
# ssl_certificate / ssl_certificate_key ...
|
||||
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:8787;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
|
||||
# SSE 关键项:关缓冲、长超时、HTTP/1.1
|
||||
proxy_buffering off;
|
||||
proxy_cache off;
|
||||
proxy_read_timeout 3600s;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Connection "";
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
> 仅当 SSE 需要走与页面不同的来源(如独立子域)时,才在**构建期**设置 `NEXT_PUBLIC_SSE_BASE`(该变量在 `next build` 时固化进静态包,容器运行时再设无效)。
|
||||
|
||||
---
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user