Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a live service check to the anon message board #512

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 30 additions & 31 deletions apps/anonymous-message-board/server.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
require('dotenv').config();
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const helmet = require('helmet');
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const helmet = require('helmet');

const apiRoutes = require('./routes/api.js');
const fccTestingRoutes = require('./routes/fcctesting.js');
const runner = require('./test-runner');
const apiRoutes = require('./routes/api.js');
const fccTestingRoutes = require('./routes/fcctesting.js');
const runner = require('./test-runner');

const app = express();

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

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

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

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

app.route('/b/:board/:threadid')
.get(function (req, res) {
res.sendFile(process.cwd() + '/views/thread.html');
});
app.route('/b/:board/:threadid').get(function (req, res) {
res.sendFile(process.cwd() + '/views/thread.html');
});

// Index page (static HTML)
app.route('/')
.get(function (req, res) {
res.sendFile(process.cwd() + '/views/index.html');
});
app.route('/').get(function (req, res) {
res.sendFile(process.cwd() + '/views/index.html');
});

app.get('/status/ping', (req, res) => {
res.send({ msg: 'pong' }).status(200);
});

// For FCC testing purposes
fccTestingRoutes(app);

// Routing for API
// Routing for API
apiRoutes(app);

// 404 Not Found middleware
app.use(function(req, res) {
res.status(404)
.type('text')
.send('Not Found');
app.use(function (req, res) {
res.status(404).type('text').send('Not Found');
});

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

// Start our server and tests
app.listen(portNum, function () {
console.log("Listening on port " + portNum);
if(process.env.NODE_ENV==='test') {
console.log('Listening on port ' + portNum);
if (process.env.NODE_ENV === 'test') {
console.log('Running Tests...');
setTimeout(function () {
try {
runner.run();
} catch(e) {
} catch (e) {
const error = e;
console.log('Tests are not valid:');
console.log(error);
console.log('Tests are not valid:');
console.log(error);
}
}, 1500);
}
Expand Down