From ee675a0e84035d239fb2b7f19c427d64663a7de1 Mon Sep 17 00:00:00 2001 From: Minu Mathew Date: Thu, 7 May 2026 15:51:42 -0500 Subject: [PATCH 1/3] stashed change on app.js --- server/app.js | 28 +++++++++++++++++--- src/components/previewers/Pdf.js | 2 +- src/routes.tsx | 45 ++++++++++++++++++++++++++------ 3 files changed, 62 insertions(+), 13 deletions(-) diff --git a/server/app.js b/server/app.js index 300af9e..6d5b62e 100644 --- a/server/app.js +++ b/server/app.js @@ -136,9 +136,11 @@ app.use('/', authRouter); app.use('/', clowderRouter); app.use('/api/rctdb', rctdbRouter); -app.use('/home',express.static('../dist')); -app.use('/public',express.static('../dist/public')); -app.use('/public', express.static('public')); +// Serve built assets from root so relative-path bundle references work on any page +app.use(express.static(path.join(__dirname, '../dist'))); +app.use('/home',express.static(path.join(__dirname, '../dist'))); +app.use('/public',express.static(path.join(__dirname, '../dist/public'))); +app.use('/public', express.static(path.join(__dirname, 'public'))); app.get('/client',ensureLoggedIn, function (req, res, next){ @@ -159,7 +161,25 @@ app.get('/home', ensureLoggedIn, function (req, res, next){ res.sendFile(path.join(__dirname, '../dist', 'index.html')); }); -// catch 404 and forward to error handler +app.get('/preview', ensureLoggedIn, function (req, res, next){ + res.sendFile(path.join(__dirname, '../dist', 'index.html')); +}); + +// SPA fallback: serve React app for any unmatched non-API, non-asset route so +// that client-side routes (React Router) work on direct navigation / refresh. +// Requests with a file extension (JS, CSS, images, etc.) are NOT intercepted — +// those should 404 rather than receiving index.html (which causes "Unexpected token '<'"). +app.use(function(req, res, next) { + if (req.path.startsWith('/api/')) { + return next(createError(404)); + } + if (path.extname(req.path)) { + return next(createError(404)); + } + res.sendFile(path.join(__dirname, '../dist', 'index.html')); +}); + +// catch 404 and forward to error handler (API routes only reach here) app.use(function(req, res, next) { next(createError(404)); }); diff --git a/src/components/previewers/Pdf.js b/src/components/previewers/Pdf.js index be3b372..4b43eae 100644 --- a/src/components/previewers/Pdf.js +++ b/src/components/previewers/Pdf.js @@ -509,7 +509,7 @@ export default function Pdf(props) { {/* Relative positioning container for PDF and overlay canvas with scrollable content */}
+ + 404 + + + Page not found + + + The page you're looking for doesn't exist or has been moved. + + + + ); +} export const AppRoutes = (): JSX.Element => { return ( @@ -14,13 +49,7 @@ export const AppRoutes = (): JSX.Element => { {/* }/> */} } /> } /> - -

Page Not Found!

- - } - /> + } /> ); From 6d46381dd3be99d5ca724e9408c6b7ea5039d841 Mon Sep 17 00:00:00 2001 From: Minu Mathew Date: Thu, 7 May 2026 15:54:42 -0500 Subject: [PATCH 2/3] have preview route in server --- server/app.js | 1 + 1 file changed, 1 insertion(+) diff --git a/server/app.js b/server/app.js index 6d5b62e..fea3f2c 100644 --- a/server/app.js +++ b/server/app.js @@ -139,6 +139,7 @@ app.use('/api/rctdb', rctdbRouter); // Serve built assets from root so relative-path bundle references work on any page app.use(express.static(path.join(__dirname, '../dist'))); app.use('/home',express.static(path.join(__dirname, '../dist'))); +app.use('/preview',express.static(path.join(__dirname, '../dist'))); app.use('/public',express.static(path.join(__dirname, '../dist/public'))); app.use('/public', express.static(path.join(__dirname, 'public'))); From 7b6a7c2888a589b147e9e24ba62bbb025ab560d8 Mon Sep 17 00:00:00 2001 From: Minu Mathew Date: Thu, 7 May 2026 15:56:24 -0500 Subject: [PATCH 3/3] remove preview route --- server/app.js | 1 - 1 file changed, 1 deletion(-) diff --git a/server/app.js b/server/app.js index fea3f2c..6d5b62e 100644 --- a/server/app.js +++ b/server/app.js @@ -139,7 +139,6 @@ app.use('/api/rctdb', rctdbRouter); // Serve built assets from root so relative-path bundle references work on any page app.use(express.static(path.join(__dirname, '../dist'))); app.use('/home',express.static(path.join(__dirname, '../dist'))); -app.use('/preview',express.static(path.join(__dirname, '../dist'))); app.use('/public',express.static(path.join(__dirname, '../dist/public'))); app.use('/public', express.static(path.join(__dirname, 'public')));