-
Notifications
You must be signed in to change notification settings - Fork 22
/
index.js
43 lines (35 loc) · 1.08 KB
/
index.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
var debug = require('debug')('frontend-code-challenge');
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var logger = require('./lib/logger');
var users = require('./routes/users');
var app = express();
var log = logger(app);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/users', users);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// development error handler
// will print stacktrace
app.use(function(err, req, res, next) {
log.error(err);
res.status(err.status || 500);
res.json({
message: err.message,
error: err
});
});
app.set('port', process.env.PORT || 3000);
var server = app.listen(app.get('port'), function() {
log.info('Express server listening on http://localhost:%d', server.address().port);
});