Skip to content

Commit

Permalink
Disabling SSR for the time being.
Browse files Browse the repository at this point in the history
  • Loading branch information
krulis-martin committed Jan 26, 2024
1 parent ad7b17b commit c262b4b
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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, {
Expand All @@ -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);
Expand Down

0 comments on commit c262b4b

Please sign in to comment.