-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
53 lines (43 loc) · 1.28 KB
/
app.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
'use strict';
var express = require('express')
, app = express()
, bodyParser = require('body-parser')
, cors = require('cors')
, http = require('http')
, methodOverride = require('method-override')
, server;
exports.start = function() {
// all environments
app.set('port', process.env.PORT || 2808);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.text({ type: 'text/plain' }));
app.use(methodOverride());
// enable CORS header
app.use(cors({
credentials: true,
origin: 'http://localhost:' + app.get('port'),
exposedHeaders: ['Location'],
}));
// enable pre-flight for put/patch/delete
app.options('*', cors());
app.get('/quit', function(req, res) {
res.status(204).end();
console.log('Received request to /quit, shutting down.');
exports.stop();
});
// include routes
app.use(require('./routes'));
global.port = app.get('port');
server = http.createServer(app);
server.listen(app.get('port'), function() {
console.log('Traverson test server listening on port ' + app.get('port'));
});
};
exports.stop = function() {
console.log('Stopping Traverson test server.');
server.close();
};
exports.serveStatic = function(dir) {
app.use('/static', express.static(dir));
}