mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-13 04:06:59 +00:00
fix: remote proxy strips /api prefix causing remote Sencho to return SPA HTML
app.use('/api/', ...) causes Express to strip the '/api/' prefix from
req.url before http-proxy-middleware sees it, so the proxy was forwarding
'/stats' to the remote instead of '/api/stats'. The remote Sencho found
no matching route, fell through to its SPA catch-all, and returned
index.html (200 text/html) — explaining the SyntaxError on res.json().
Added pathRewrite: (path) => '/api' + path to restore the full path.
The connection test passed because testRemoteConnection calls the remote
directly via axios with the full URL, bypassing the proxy entirely.
This commit is contained in:
@@ -331,6 +331,10 @@ const remoteNodeProxy = createProxyMiddleware<Request, Response>({
|
||||
const node = NodeRegistry.getInstance().getNode(req.nodeId);
|
||||
return node?.api_url?.replace(/\/$/, '');
|
||||
},
|
||||
// When mounted at app.use('/api/', ...), Express strips the '/api/' prefix from
|
||||
// req.url before the middleware sees it. Re-add it so the remote Sencho instance
|
||||
// receives the full path (e.g. '/stats' becomes '/api/stats').
|
||||
pathRewrite: (path) => '/api' + path,
|
||||
on: {
|
||||
proxyReq: (proxyReq, req) => {
|
||||
const node = NodeRegistry.getInstance().getNode(req.nodeId);
|
||||
|
||||
Reference in New Issue
Block a user