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 = { ...@@ -233,6 +233,15 @@ module.exports = {
chunks: ['vendor', 'common', 'catalog'], chunks: ['vendor', 'common', 'catalog'],
favicon: 'favicon.ico' 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 // Defer/Async scripts
new ScriptExtHtmlWebpackPlugin({ new ScriptExtHtmlWebpackPlugin({
......
...@@ -28,7 +28,7 @@ import config from '../config'; ...@@ -28,7 +28,7 @@ import config from '../config';
import checkAuthToken from './checkAuthToken'; import checkAuthToken from './checkAuthToken';
import {configure} from 'actions/applicationConfig'; import {configure} from 'actions/applicationConfig';
const prerenderer = (html) => (req, res) => { const prerenderer = (html, errHtml) => (req, res) => {
console.log('Init prerenderer, request url:', req.url); console.log('Init prerenderer, request url:', req.url);
const startTime = Date.now(); const startTime = Date.now();
res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Origin', '*');
...@@ -138,7 +138,17 @@ const prerenderer = (html) => (req, res) => { ...@@ -138,7 +138,17 @@ const prerenderer = (html) => (req, res) => {
console.error('Error:', err); console.error('Error:', err);
res.status(500).end(err.message); 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; export default prerenderer;
...@@ -18,6 +18,7 @@ const app = express(); ...@@ -18,6 +18,7 @@ const app = express();
// This reads the ssr-template.html compiled to ssr-compiled.html by webpack // 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')}`); 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 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 // Log all requests
app.use((req, res, next) => { app.use((req, res, next) => {
...@@ -58,6 +59,6 @@ app.use(i18nextMiddleware.handle(i18nServer)); ...@@ -58,6 +59,6 @@ app.use(i18nextMiddleware.handle(i18nServer));
// Parse cookies // Parse cookies
app.use(cookieParser()); app.use(cookieParser());
// Relay requests to React // Relay requests to React
app.use(prerenderer(html)); app.use(prerenderer(html, errHtml));
export default app; 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