From c262b4bee47466eb804b0a76da6762388dafb112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kruli=C5=A1?= Date: Fri, 26 Jan 2024 16:42:18 +0100 Subject: [PATCH] Disabling SSR for the time being. --- src/server.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/server.js b/src/server.js index 6048a7d13..63758fc84 100644 --- a/src/server.js +++ b/src/server.js @@ -65,6 +65,11 @@ app.use( ); app.use(cookieParser()); +/** + * Note: this method was originally created to support SSR (serialize store as well). + * At present, we have no additional support for SSR and some features (like user IP locking) + * will not work at all. SSR may be reintroduce in the future, but this should be rewritten. + */ const renderPage = (res, store = null, html = '') => { const reduxState = store ? serialize(store.getState(), { isJSON: true }) : 'undefined'; const head = Helmet.rewind(); @@ -86,16 +91,26 @@ app.get('*', (req, res) => { const lang = req.cookies[LANG_COOKIES_KEY] || null; // Selected instance const store = configureStore(undefined, token, instanceId, lang); const location = req.originalUrl; - const context = {}; try { + /* + * Important! + * Parts that were responsible for SSR were disabled on 26.1.2024. + * SSR were not working properly and new API features (IP locking) were introduced + * that are not SSR ready. + * We keep the original code commented, so this may be fixed in the future. + */ + const userId = loggedInUserIdSelector(store.getState()); // try to get the user ID from the token (if any) - const isSuperadmin = isLoggedAsSuperAdmin(store.getState()); - const { redirect, params, loadAsync } = match(location, Boolean(userId)); + const { redirect /*, params, loadAsync */ } = match(location, Boolean(userId)); + // const isSuperadmin = isLoggedAsSuperAdmin(store.getState()); + // const context = {}; if (redirect) { res.redirect(302, redirect); } else { + renderPage(res); + /* Promise.all( loadAsync.map(la => la(params, store.dispatch, { @@ -116,6 +131,7 @@ app.get('*', (req, res) => { renderPage(res, store, html); }) .catch(() => renderPage(res)); // without SSR + */ } } catch (error) { res.status(500).send(error.message);