-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoke.js
36 lines (33 loc) · 1.32 KB
/
poke.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
// playground for poking on arbitray mongodb backends
// node poke.js // in nitrous.io
// https://s3ql-70726.use1.nitrousbox.com/ // nitrous.io will proxy port 3000 through SSL
var mongodb = require("mongodb");
var http = require("http");
var corser = require("corser");
var log = console.log;
var port = process.env.PORT || 3000; // nitrous will proxy it through SSL through this port
log('POSTmongo served at port '+port);
log('service at https://s3ql-70726.use1.nitrousbox.com');
// Create Corser request listener.
var corserRequestListener = corser.create();
http.createServer(function (req, res) {
// Route req and res through the request listener.
corserRequestListener(req, res, function () {
if (req.method === "OPTIONS") {
// End CORS preflight request.
res.writeHead(204);
res.end();
} else {
res.writeHead(200);
res.write('poking mongodb');
res.write('\n');
res.write(req.url);
var pp = req.url.slice(2).split('&').map(function(xi){return xi.split('=')});
var parm={};
pp.map(function(xi){parm[xi[0]]=decodeURI(xi[1])});
res.write('\nparm=');
res.write(JSON.stringify(parm));
res.end();
}
});
}).listen(port);