-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathindex.js
41 lines (34 loc) · 883 Bytes
/
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
#!/bin/env node
var http, director, bot, router, server, port, db;
http = require('http');
director = require('director');
bot = require('./bot.js');
router = new director.http.Router({
'/' : {
get: ping
},
'/commands' : {
get: bot.commands
},
'/bot/:botRoom' : {
get: ping,
post: bot.respond
},
});
server = http.createServer(function (req, res) {
req.chunks = [];
req.on('data', function (chunk) {
req.chunks.push(chunk.toString());
});
router.dispatch(req, res, function(err) {
res.writeHead(err.status, {"Content-Type": "text/plain"});
res.end(err.message);
});
});
port = Number(process.env.OPENSHIFT_NODEJS_PORT || process.env.PORT || 3002);
ip = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";
server.listen(port, ip);
function ping() {
this.res.writeHead(200);
this.res.end("I am a robot.");
}