fix(server): serve cached index.html in SPA catch-all to prevent 500
res.sendFile can emit NotFoundError from the send module in certain path resolution scenarios, causing 500s on company-scoped SPA routes. Cache index.html at startup and serve it directly, which is both more reliable and faster. Fixes #233 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -134,9 +134,10 @@ export async function createApp(
|
|||||||
];
|
];
|
||||||
const uiDist = candidates.find((p) => fs.existsSync(path.join(p, "index.html")));
|
const uiDist = candidates.find((p) => fs.existsSync(path.join(p, "index.html")));
|
||||||
if (uiDist) {
|
if (uiDist) {
|
||||||
|
const indexHtml = fs.readFileSync(path.join(uiDist, "index.html"), "utf-8");
|
||||||
app.use(express.static(uiDist));
|
app.use(express.static(uiDist));
|
||||||
app.get(/.*/, (_req, res) => {
|
app.get(/.*/, (_req, res) => {
|
||||||
res.sendFile("index.html", { root: uiDist });
|
res.status(200).set("Content-Type", "text/html").end(indexHtml);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.warn("[paperclip] UI dist not found; running in API-only mode");
|
console.warn("[paperclip] UI dist not found; running in API-only mode");
|
||||||
|
|||||||
Reference in New Issue
Block a user