aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/app.js
diff options
context:
space:
mode:
authorMarvin Borner2019-01-18 21:07:39 +0100
committerMarvin Borner2019-01-18 21:07:39 +0100
commit7dd78773cb6c0c3ccfa6784fde98e4ad923b0bc9 (patch)
tree09083cadac80892a759776cf6ef3b030400f23ab /src/app.js
Initial boilerplate
Diffstat (limited to 'src/app.js')
-rw-r--r--src/app.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/app.js b/src/app.js
new file mode 100644
index 0000000..6eb3445
--- /dev/null
+++ b/src/app.js
@@ -0,0 +1,40 @@
+import express from 'express';
+import path from 'path';
+import logger from 'morgan';
+import bodyParser from 'body-parser';
+import routes from './routes';
+
+const app = express();
+app.disable('x-powered-by');
+
+// View engine setup
+app.set('views', path.join(__dirname, '../views'));
+app.set('view engine', 'pug');
+
+app.use(logger('dev', {
+ skip: () => app.get('env') === 'test'
+}));
+app.use(bodyParser.json());
+app.use(bodyParser.urlencoded({extended: false}));
+app.use(express.static(path.join(__dirname, '../public')));
+
+// Routes
+app.use('/', routes);
+
+// Catch 404 and forward to error handler
+app.use((req, res, next) => {
+ const err = new Error('Not Found');
+ err.status = 404;
+ next(err);
+});
+
+// Error handler
+app.use((err, req, res, next) => { // eslint-disable-line no-unused-vars
+ res
+ .status(err.status || 500)
+ .render('error', {
+ message: err.message
+ });
+});
+
+export default app;