-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.js
More file actions
32 lines (22 loc) · 743 Bytes
/
Server.js
File metadata and controls
32 lines (22 loc) · 743 Bytes
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
#!/bin/env node
var restify = require ('restify'),
db = require ('./MyDb');
var my_db = new db ("127.0.0.1", 27017);
// console.log (my_db;)
function respond(req, res, next, obj) {
// TODO: receive record and save to database
req.on("data", function(data) {
console.log (JSON.stringify(eval('('+data.toString()+')')));
my_db.insert (JSON.stringify(eval('('+data.toString()+')')), function (err, str){
res.send (str);
});
});
req.on("exit", function(code){
console.log ("req exit with code: " + code);
});
}
var server = restify.createServer();
server.post('/recall/v1/record', respond);
server.listen(8080, function() {
console.log('%s listening at %s', server.name, server.url);
});