-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
39 lines (35 loc) · 1.2 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
//jshint node: true
var express = require('express'),
http = require('http'),
bodyParser = require('body-parser'),
activity = require('./lib/index'),
app, port, host, httpServer;
process.on('uncaughtException', function (err) {
"use strict";
console.error("Uncaught Exception");
console.error(err);
console.error(err.stack);
});
app = express();
app.use(bodyParser.json({limit: '10mb'}));
app.use(bodyParser.urlencoded({limit: '10mb', extended: false}));
port = process.env.PORT || 9250;
host = process.env.HOST || "127.0.0.1";
// Serve samples
if (process.env.SAMPLE) {
app.use(express.static(__dirname + '/sample/'));
}
// Enable CORS
app.use(function (req, res, next) {
"use strict";
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET,POST,DELETE,OPTIONS");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, X-Requester");
next();
});
// Starts the server itself
httpServer = http.createServer(app).listen(port, host, function () {
"use strict";
console.log("Server listening to %s:%d within %s environment", host, port, app.get('env'));
});
app.use(activity({httpServer: httpServer}));