22import 'cross-fetch/polyfill' ;
33
44// server setup
5- import React from 'react' ;
6- import { Provider } from 'react-redux' ;
7- import { renderToString } from 'react-dom/server' ;
85import serialize from 'serialize-javascript' ;
96import Express from 'express' ;
107import ejs from 'ejs' ;
11- import Promise from 'bluebird' ;
128import Helmet from 'react-helmet' ;
139import cookieParser from 'cookie-parser' ;
1410import fs from 'fs' ;
1511import { globSync } from 'glob' ;
1612
17- import { StaticRouter } from 'react-router-dom/server' ;
18-
1913import { configureStore } from './redux/store' ;
2014import { loggedInUserIdSelector } from './redux/selectors/auth' ;
21- import { isLoggedAsSuperAdmin } from './redux/selectors/users' ;
2215import { match } from './pages/routes' ;
2316import { TOKEN_COOKIES_KEY , INSTANCEID_COOKIES_KEY } from './redux/middleware/authMiddleware' ;
2417import { LANG_COOKIES_KEY } from './redux/middleware/langMiddleware' ;
25- import App from './containers/App' ;
2618
2719import '@formatjs/intl-pluralrules/polyfill' ;
2820import '@formatjs/intl-pluralrules/locale-data/en' ;
@@ -65,6 +57,11 @@ app.use(
6557) ;
6658app . use ( cookieParser ( ) ) ;
6759
60+ /**
61+ * Note: this method was originally created to support SSR (serialize store as well).
62+ * At present, we have no additional support for SSR and some features (like user IP locking)
63+ * will not work at all. SSR may be reintroduce in the future, but this should be rewritten.
64+ */
6865const renderPage = ( res , store = null , html = '' ) => {
6966 const reduxState = store ? serialize ( store . getState ( ) , { isJSON : true } ) : 'undefined' ;
7067 const head = Helmet . rewind ( ) ;
@@ -86,16 +83,26 @@ app.get('*', (req, res) => {
8683 const lang = req . cookies [ LANG_COOKIES_KEY ] || null ; // Selected instance
8784 const store = configureStore ( undefined , token , instanceId , lang ) ;
8885 const location = req . originalUrl ;
89- const context = { } ;
9086
9187 try {
88+ /*
89+ * Important!
90+ * Parts that were responsible for SSR were disabled on 26.1.2024.
91+ * SSR were not working properly and new API features (IP locking) were introduced
92+ * that are not SSR ready.
93+ * We keep the original code commented, so this may be fixed in the future.
94+ */
95+
9296 const userId = loggedInUserIdSelector ( store . getState ( ) ) ; // try to get the user ID from the token (if any)
93- const isSuperadmin = isLoggedAsSuperAdmin ( store . getState ( ) ) ;
94- const { redirect, params, loadAsync } = match ( location , Boolean ( userId ) ) ;
97+ const { redirect /*, params, loadAsync */ } = match ( location , Boolean ( userId ) ) ;
98+ // const isSuperadmin = isLoggedAsSuperAdmin(store.getState());
99+ // const context = {};
95100
96101 if ( redirect ) {
97102 res . redirect ( 302 , redirect ) ;
98103 } else {
104+ renderPage ( res ) ;
105+ /*
99106 Promise.all(
100107 loadAsync.map(la =>
101108 la(params, store.dispatch, {
@@ -116,6 +123,7 @@ app.get('*', (req, res) => {
116123 renderPage(res, store, html);
117124 })
118125 .catch(() => renderPage(res)); // without SSR
126+ */
119127 }
120128 } catch ( error ) {
121129 res . status ( 500 ) . send ( error . message ) ;
0 commit comments