Commit 23eacf6a authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '62-ssr-oh-oh-page' into 'master'

Resolve "SSR: Oh-Oh page"

Closes #62

See merge request genesys-pgr/genesys-ui!64
parents d8919a52 9026ee1f
......@@ -233,6 +233,15 @@ module.exports = {
chunks: ['vendor', 'common', 'catalog'],
favicon: 'favicon.ico'
}),
new HtmlWebpackPlugin({
title: 'Genesys', // The title to use for the generated HTML document
filename: 'ssr-error.html', // The file to write the HTML to
xhtml: true,
excludeAssets: [/server(\..+)*\.ts/],
chunks: [],
template: './server/ssr-error.html',
favicon: 'favicon.ico'
}),
// Defer/Async scripts
new ScriptExtHtmlWebpackPlugin({
......
......@@ -28,7 +28,7 @@ import config from '../config';
import checkAuthToken from './checkAuthToken';
import {configure} from 'actions/applicationConfig';
const prerenderer = (html) => (req, res) => {
const prerenderer = (html, errHtml) => (req, res) => {
console.log('Init prerenderer, request url:', req.url);
const startTime = Date.now();
res.header('Access-Control-Allow-Origin', '*');
......@@ -138,7 +138,17 @@ const prerenderer = (html) => (req, res) => {
console.error('Error:', err);
res.status(500).end(err.message);
});
}).catch((err) => {
console.error('Error:', err.message);
const errFilledHtml = makeErrorHtml(errHtml, err);
res.status(503).set('Content-Type', 'text/html').send(errFilledHtml);
});
};
const makeErrorHtml = (template, error) => {
const theFilledHtml = template.replace('ERROR_MESSAGE', error.message.replace('500', '503')).replace('ERROR_DETAILS', error.response.data);
return theFilledHtml;
};
export default prerenderer;
......@@ -18,6 +18,7 @@ const app = express();
// This reads the ssr-template.html compiled to ssr-compiled.html by webpack
console.log(`Reading SSR template from ${path.join('../assets', 'ssr-compiled.html')}`);
const html = readFileSync(path.join('../assets', 'ssr-compiled.html'), {encoding: 'utf8'}).replace('FRONTEND_PATH', `${config.frontendPath}/`);
const errHtml = readFileSync(path.join('../assets', 'ssr-error.html'), {encoding: 'utf8'}).replace('FRONTEND_PATH', `${config.frontendPath}/`);
// Log all requests
app.use((req, res, next) => {
......@@ -58,6 +59,6 @@ app.use(i18nextMiddleware.handle(i18nServer));
// Parse cookies
app.use(cookieParser());
// Relay requests to React
app.use(prerenderer(html));
app.use(prerenderer(html, errHtml));
export default app;
<!DOCTYPE html>
<html lang=SERVER_RENDERED_LANG dir=SERVER_RENDERED_DIR>
<head>
<title>Oh oh</title>
<base href="FRONTEND_PATH" />
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes" />
<meta name="author" content="Genesys Team, helpdesk@genesys-pgr.org" />
<style type="text/css" id="server-side-styles">
body {
font-family: 'Roboto', sans-serif;
padding: 0 !important;
margin: 0;
background: #e7e5df;
overflow-y: scroll !important;
}
</style>
</head>
<body>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<div>
<h1>ERROR_MESSAGE</h1>
<p>ERROR_DETAILS</p>
<p>The server is currently unavailable (because it is overloaded or down for maintenance). Generally, this is a temporary state.</p>
</div>
</body>
</html>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment