-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
47 lines (37 loc) · 1.17 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
(function () {
"use strict";
var restify = require('restify'),
bunyan = require('bunyan'),
api = require('./controller/api.js');
// Get the environment variables we need.
var host = process.env.VCAP_APP_HOST || 'localhost';
var port = process.env.VCAP_APP_PORT || 3005;
var logger = bunyan.createLogger({
name: 'Mobile Sumobot',
streams: [
{
level: process.env.LOG_LEVEL || 'info',
stream: process.stdout
},
{
level: 'error',
stream: process.stderr
}
]
});
var server = restify.createServer({
name: 'Mobile Sumobot',
version: '0.0.1',
log: logger
});
logger.info("Starting up " + server.name + " " + server.version);
// Cleans up sloppy paths
server.pre(restify.pre.sanitizePath());
server.use(restify.acceptParser(server.acceptable));
server.use(restify.queryParser());
// Service API
server.get('/operate/:cmd', api.command);
server.listen(port, host, function () {
console.log('%s listening at %s', server.name, server.url);
});
})();