fix(portal): middleware 兼容 query string (/ssw/tds/?redirect=... 命中门户页)

根因: 苏苏访问 /ssw/tds/?redirect=... 时 vite middleware 未命中 (旧正则 $ 要求 URL
精确以 /ssw/tds/ 结尾, query 干扰), 落到 SPA fallback 返回 jweb SPA 入口 HTML (4559),
浏览器启动 jweb SPA 后 router 守卫 'if (!userStore.userInfo) return LOGIN_PATH',
把用户重定向到 /login?redirect=... 双重 URL 编码原 URL.

修复: 正则改成 /^\/ssw/(tds|tdc|sswflow)\/?(\?|$)/, 允许结尾是 ? 或 $;
非捕获组 (?:\?|$) 改成捕获组 (\?|$) 让 $1 能引用 ?.
replace: u.replace(/\/?(\?|$)/, '/index.html$1'), query 透传到 index.html.

验证: /ssw/tds/, /ssw/tds/?redirect=..., /ssw/tds/?foo=bar, /ssw/tds/index.html
四个 URL 两栈都 200 + 50169 bytes 命中 jweb 真源门户页.
This commit is contained in:
admin committed 2026-08-08 09:19:42 +08:00
1 parent a9be499033
commit 48ef4765e7
2 files changed
+6 -4

No files matched your search

+3 -2
View File
@@ -35,8 +35,9 @@ export default defineConfig(async () => {
configureServer(server) {
server.middlewares.use((req, res, next) => {
const u = req.url || ''
if (/^\/ssw\/(tds|tdc|sswflow)\/?$/.test(u)) {
req.url = u.replace(/\/?$/, '/index.html')
// 允许 query string: /ssw/tds/?redirect=... 也命中门户页
if (/^\/ssw\/(tds|tdc|sswflow)\/?(\?|$)/.test(u)) {
req.url = u.replace(/\/?(\?|$)/, '/index.html$1')
res.setHeader('Cache-Control', 'no-store')
}
next()
+3 -2
View File
@@ -39,8 +39,9 @@ export default defineConfig({
configureServer(server) {
server.middlewares.use((req, res, next) => {
const u = req.url || ''
if (/^\/ssw\/(tds|tdc|sswflow)\/?$/.test(u)) {
req.url = u.replace(/\/?$/, '/index.html')
// 允许 query string: /ssw/tds/?redirect=... 也命中门户页
if (/^\/ssw\/(tds|tdc|sswflow)\/?(\?|$)/.test(u)) {
req.url = u.replace(/\/?(\?|$)/, '/index.html$1')
res.setHeader('Cache-Control', 'no-store')
}
next()