@apolitical/server 2.2.0-rc.fallback.2 → 2.2.0-rc.fallback.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apolitical/server",
|
|
3
|
-
"version": "2.2.0-rc.fallback.
|
|
3
|
+
"version": "2.2.0-rc.fallback.3",
|
|
4
4
|
"description": "Node.js module to encapsulate Apolitical's express server setup",
|
|
5
5
|
"author": "Apolitical Group Limited <engineering@apolitical.co>",
|
|
6
6
|
"license": "MIT",
|
package/src/container.js
CHANGED
|
@@ -36,7 +36,7 @@ const documentationLoader = require('./loaders/documentation.loader');
|
|
|
36
36
|
const loggerLoader = require('./loaders/logger.loader');
|
|
37
37
|
const middlewaresLoader = require('./loaders/middlewares.loader');
|
|
38
38
|
const probesLoader = require('./loaders/probes.loader');
|
|
39
|
-
const
|
|
39
|
+
const fallbackController = require('./controllers/fallback.controller');
|
|
40
40
|
// Middleware
|
|
41
41
|
const authenticationMiddleware = require('./middlewares/authentication.middleware');
|
|
42
42
|
const authorisationMiddleware = require('./middlewares/authorisation.middleware');
|
|
@@ -85,7 +85,7 @@ container.register({
|
|
|
85
85
|
loggerLoader: asFunction(loggerLoader).singleton(),
|
|
86
86
|
middlewaresLoader: asFunction(middlewaresLoader).singleton(),
|
|
87
87
|
probesLoader: asFunction(probesLoader).singleton(),
|
|
88
|
-
|
|
88
|
+
fallbackController: asFunction(fallbackController).singleton(),
|
|
89
89
|
// Middlewares
|
|
90
90
|
authenticationMiddleware: asFunction(authenticationMiddleware).singleton(),
|
|
91
91
|
authorisationMiddleware: asFunction(authorisationMiddleware).singleton(),
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
module.exports = ({ logger }) => {
|
|
4
|
-
return function load(app, {
|
|
4
|
+
return function load(app, { fallbackController, staticFiles }) {
|
|
5
5
|
const childLogger = logger.where(__filename, 'load');
|
|
6
6
|
childLogger.debug('Started');
|
|
7
7
|
|
|
8
8
|
if (staticFiles) {
|
|
9
9
|
const { baseUrl, indexFilePath } = staticFiles;
|
|
10
10
|
// Load fallback or static content
|
|
11
|
-
if (
|
|
12
|
-
app.get(`${baseUrl}*`,
|
|
11
|
+
if (fallbackController) {
|
|
12
|
+
app.get(`${baseUrl}*`, fallbackController);
|
|
13
13
|
} else if (indexFilePath) {
|
|
14
14
|
app.get(`${baseUrl}*`, function (req, res) {
|
|
15
15
|
res.sendFile(indexFilePath);
|
|
@@ -9,7 +9,7 @@ module.exports =
|
|
|
9
9
|
logger,
|
|
10
10
|
serverError: { GeneralError },
|
|
11
11
|
}) =>
|
|
12
|
-
({ labels, redirectURL }) => {
|
|
12
|
+
({ labels, redirectURL, fallbackController }) => {
|
|
13
13
|
// Apolitical Logger (with service metadata)
|
|
14
14
|
const errorLogger = logger.where(__filename, 'errorMiddleware', labels);
|
|
15
15
|
|
|
@@ -43,8 +43,11 @@ module.exports =
|
|
|
43
43
|
} else {
|
|
44
44
|
errorLogger.warn(message, { errors });
|
|
45
45
|
}
|
|
46
|
+
|
|
46
47
|
if (redirectURL) {
|
|
47
48
|
res.redirect(TEMPORARY_REDIRECT, `${redirectURL}?errorMessage=${encodeURI(message)}`);
|
|
49
|
+
} else if (fallbackController && message === 'Unexpected error: Cannot read items') {
|
|
50
|
+
fallbackController(req, res);
|
|
48
51
|
} else {
|
|
49
52
|
res.status(code).json({ message, errors });
|
|
50
53
|
}
|
|
@@ -11,7 +11,7 @@ module.exports = ({
|
|
|
11
11
|
errorMiddleware,
|
|
12
12
|
middlewaresLoader,
|
|
13
13
|
probesLoader,
|
|
14
|
-
|
|
14
|
+
fallbackController,
|
|
15
15
|
jwtService,
|
|
16
16
|
serverError,
|
|
17
17
|
}) => {
|
|
@@ -54,7 +54,7 @@ module.exports = ({
|
|
|
54
54
|
documentationLoader(app, opts);
|
|
55
55
|
|
|
56
56
|
// Load static resources or fallback
|
|
57
|
-
|
|
57
|
+
fallbackController(app, opts);
|
|
58
58
|
|
|
59
59
|
// Use error handler
|
|
60
60
|
if (opts.handleErrors) {
|