This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathappSetup.js
72 lines (67 loc) · 1.97 KB
/
appSetup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const morgan = require('morgan');
const path = require('path');
const devErrorHandler = require('errorhandler');
const ftwebservice = require('express-ftwebservice');
const healthcheck = require('./health/healthchecks');
// catch 404 and forward to error handler
const notFoundHandler = function(req, res, next) {
const err = new Error('Not Found');
err.status = 404;
next(err);
};
const errorHandler = (err, req, res, next) => {
res.set('Cache-Control', 'private, no-cache, no-store');
if (err.status === 404) {
res.status(404).send("Not found");
} else {
res.status(503).send('<p>Internal Server Error</p>');
console.error(err.stack);
next(err);
}
};
module.exports = (app, config) => {
ftwebservice(app, {
manifestPath: path.join(__dirname, 'package.json'),
about: {
"schemaVersion": 1,
"name": "ftalphaville-es-interface-service",
"purpose": "Serving article data from Next Elastic and Alphaville Wordpress with Alphaville specific transformations.",
"audience": "public",
"primaryUrl": "https://ftalphaville-es-interface-service.ft.com",
"serviceTier": "bronze"
},
goodToGoTest: function() {
return new Promise(function(resolve) {
resolve(true);
});
},
healthCheck: function() {
return healthcheck.getChecks().then(checks => {
return checks;
}).catch((err) => {
console.log(err);
return [
{
name: "Healthcheck",
ok: false,
severity: 2,
businessImpact: "Some areas of the application might be unavailable due to the issue.",
technicalSummary: "Healthcheck is not available.",
panicGuide: "Check the logs of the application, try to restart it from heroku.",
checkOutput: "Healthcheck generation failed.",
lastUpdated: new Date().toISOString()
}
];
});
}
});
if (config.env === config.dev) {
app.use(notFoundHandler);
app.use(errorHandler);
app.use(devErrorHandler());
app.use(morgan('dev'));
} else {
app.use(notFoundHandler);
app.use(errorHandler);
}
};