UNPKG

1.11 kBJavaScriptView Raw
1const paths = require("../../config/paths");
2const path = require("path");
3
4module.exports = ({app,express})=>{
5 const serverRendering = app.get('view engine');
6
7
8 app.get('/health', function (req, res, next) {
9 //TODO: Put some kind of actualy deeper check to make sure server is still healthy.
10 return res.status(200).json({statusCode:200});
11 });
12
13 app.get('*', function (req, res,next) {
14
15 //Handle Server Rendering is enabled on the server
16 if(serverRendering){
17
18 let errors = "";
19
20 if(req.session && req.session.error){
21 errors = req.session.error;
22 delete req.session.error
23 }
24
25 return res.render('index', Object.assign({
26 layout:false,
27 errors:errors,
28 },res.locals));
29 }
30
31 //No server rendering assume html is build dir
32 res.sendFile(path.join(paths.appBuild, 'index.html'),{},(err)=>{
33 if (err) {
34 res.sendFile(path.join(paths.appMiddleware,"express","NotFound.html"));
35 }
36 });
37 });
38
39 return app;
40}
\No newline at end of file