forked from jlcanela/dumbo-hal-se-summit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
54 lines (42 loc) · 1.23 KB
/
server.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
44
45
46
47
48
49
50
51
52
53
54
var http = require('http');
var express = require('express');
var morgan = require('morgan');
var bodyParser = require('body-parser');
var routes = require('./lib/routes');
module.exports = Server;
function Server (doLogRequests) {
var app = express();
app.set('json spaces', 2);
if (doLogRequests) {
app.use(morgan('dev'));
}
app.use(bodyParser.json());
app.get('/status', function (req, res) {
res.json({up: true});
});
app.post('/order', function (req, res, next) {
routes.order(req, res, next);
});
app.post('/feedback', function (req, res, next) {
routes.feedback(req, res, next);
});
app.get('/categories', function(req, res, next) {
routes.categories(req, res, next);
});
app.get('/licenses', function(req, res, next) {
routes.licenses(req, res, next);
});
app.get('/vouchers', function(req, res, next) {
routes.vouchers(req, res, next);
});
var server = http.createServer(app);
server.start = server.listen.bind(server, process.env.PORT || 3000);
server.stop = server.close.bind(server);
return server;
}
if (!module.parent) {
var server = new Server(true);
server.start(function () {
console.log('server listening on port', server.address().port);
});
}