Linted app and server.js files.
This commit is contained in:
@@ -8,7 +8,6 @@ const configuration = require('src/config/configuration').getInstance();
|
|||||||
// TODO: Have our raven router check if there is a value, if not don't enable raven.
|
// TODO: Have our raven router check if there is a value, if not don't enable raven.
|
||||||
Raven.config(configuration.get('raven', 'DSN')).install();
|
Raven.config(configuration.get('raven', 'DSN')).install();
|
||||||
|
|
||||||
|
|
||||||
const app = express(); // define our app using express
|
const app = express(); // define our app using express
|
||||||
app.use(Raven.requestHandler());
|
app.use(Raven.requestHandler());
|
||||||
// this will let us get the data from a POST
|
// this will let us get the data from a POST
|
||||||
@@ -34,27 +33,27 @@ router.use(tokenToUser);
|
|||||||
|
|
||||||
// TODO: Should have a separate middleware/router for handling headers.
|
// TODO: Should have a separate middleware/router for handling headers.
|
||||||
router.use((req, res, next) => {
|
router.use((req, res, next) => {
|
||||||
// TODO add logging of all incoming
|
// TODO add logging of all incoming
|
||||||
console.log('Request: ', req.originalUrl);
|
console.log('Request: ', req.originalUrl);
|
||||||
const origin = req.headers.origin;
|
const origin = req.headers.origin;
|
||||||
if (allowedOrigins.indexOf(origin) > -1) {
|
if (allowedOrigins.indexOf(origin) > -1) {
|
||||||
console.log('allowed');
|
console.log('allowed');
|
||||||
res.setHeader('Access-Control-Allow-Origin', origin);
|
res.setHeader('Access-Control-Allow-Origin', origin);
|
||||||
}
|
}
|
||||||
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, loggedinuser');
|
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, loggedinuser');
|
||||||
res.header('Access-Control-Allow-Methods', 'POST, GET, PUT');
|
res.header('Access-Control-Allow-Methods', 'POST, GET, PUT');
|
||||||
|
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/', function mainHandler(req, res) {
|
router.get('/', function mainHandler(req, res) {
|
||||||
throw new Error('Broke!');
|
throw new Error('Broke!');
|
||||||
});
|
});
|
||||||
|
|
||||||
app.use(Raven.errorHandler());
|
app.use(Raven.errorHandler());
|
||||||
app.use(function onError(err, req, res, next) {
|
app.use(function onError(err, req, res, next) {
|
||||||
res.statusCode = 500;
|
res.statusCode = 500;
|
||||||
res.end(res.sentry + '\n');
|
res.end(res.sentry + '\n');
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ const config = require('src/config/configuration').getInstance();
|
|||||||
const app = require('./app');
|
const app = require('./app');
|
||||||
|
|
||||||
module.exports = app.listen(config.get('webserver', 'port'), () => {
|
module.exports = app.listen(config.get('webserver', 'port'), () => {
|
||||||
console.log('seasonedAPI');
|
/* eslint-disable no-console */
|
||||||
console.log(`Database is located at ${config.get('database', 'host')}`);
|
console.log('seasonedAPI');
|
||||||
console.log(`Webserver is listening on ${config.get('webserver', 'port')}`);
|
/* eslint-disable no-console */
|
||||||
})
|
console.log(`Database is located at ${config.get('database', 'host')}`);
|
||||||
|
/* eslint-disable no-console */
|
||||||
|
console.log(`Webserver is listening on ${config.get('webserver', 'port')}`);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user