Skip to content

Commit ff20371

Browse files
authored
feat: add a live service check to the anon message board (#512)
1 parent 4c0129e commit ff20371

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

apps/anonymous-message-board/server.js

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
require('dotenv').config();
2-
const express = require('express');
3-
const bodyParser = require('body-parser');
4-
const cors = require('cors');
5-
const helmet = require('helmet');
2+
const express = require('express');
3+
const bodyParser = require('body-parser');
4+
const cors = require('cors');
5+
const helmet = require('helmet');
66

7-
const apiRoutes = require('./routes/api.js');
8-
const fccTestingRoutes = require('./routes/fcctesting.js');
9-
const runner = require('./test-runner');
7+
const apiRoutes = require('./routes/api.js');
8+
const fccTestingRoutes = require('./routes/fcctesting.js');
9+
const runner = require('./test-runner');
1010

1111
const app = express();
1212

1313
app.use('/public', express.static(process.cwd() + '/public'));
1414

15-
app.use(cors({origin: '*'})); //For FCC testing purposes only
15+
app.use(cors({ origin: '*' })); //For FCC testing purposes only
1616

1717
app.use(bodyParser.json());
1818
app.use(bodyParser.urlencoded({ extended: true }));
@@ -22,49 +22,48 @@ app.use(helmet.dnsPrefetchControl());
2222
app.use(helmet.referrerPolicy({ policy: 'same-origin' }));
2323

2424
// Sample front-end
25-
app.route('/b/:board/')
26-
.get(function (req, res) {
27-
res.sendFile(process.cwd() + '/views/board.html');
28-
});
25+
app.route('/b/:board/').get(function (req, res) {
26+
res.sendFile(process.cwd() + '/views/board.html');
27+
});
2928

30-
app.route('/b/:board/:threadid')
31-
.get(function (req, res) {
32-
res.sendFile(process.cwd() + '/views/thread.html');
33-
});
29+
app.route('/b/:board/:threadid').get(function (req, res) {
30+
res.sendFile(process.cwd() + '/views/thread.html');
31+
});
3432

3533
// Index page (static HTML)
36-
app.route('/')
37-
.get(function (req, res) {
38-
res.sendFile(process.cwd() + '/views/index.html');
39-
});
34+
app.route('/').get(function (req, res) {
35+
res.sendFile(process.cwd() + '/views/index.html');
36+
});
37+
38+
app.get('/status/ping', (req, res) => {
39+
res.send({ msg: 'pong' }).status(200);
40+
});
4041

4142
// For FCC testing purposes
4243
fccTestingRoutes(app);
4344

44-
// Routing for API
45+
// Routing for API
4546
apiRoutes(app);
46-
47+
4748
// 404 Not Found middleware
48-
app.use(function(req, res) {
49-
res.status(404)
50-
.type('text')
51-
.send('Not Found');
49+
app.use(function (req, res) {
50+
res.status(404).type('text').send('Not Found');
5251
});
5352

5453
const portNum = process.env.PORT || 3000;
5554

5655
// Start our server and tests
5756
app.listen(portNum, function () {
58-
console.log("Listening on port " + portNum);
59-
if(process.env.NODE_ENV==='test') {
57+
console.log('Listening on port ' + portNum);
58+
if (process.env.NODE_ENV === 'test') {
6059
console.log('Running Tests...');
6160
setTimeout(function () {
6261
try {
6362
runner.run();
64-
} catch(e) {
63+
} catch (e) {
6564
const error = e;
66-
console.log('Tests are not valid:');
67-
console.log(error);
65+
console.log('Tests are not valid:');
66+
console.log(error);
6867
}
6968
}, 1500);
7069
}

0 commit comments

Comments
 (0)