You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
833 B
33 lines
833 B
http = require('http');
|
|
fs = require('fs');
|
|
|
|
port = 3000;
|
|
host = '127.0.0.1';
|
|
|
|
server = http.createServer( function(req, res) {
|
|
|
|
if (req.method == 'POST') {
|
|
console.log("Handling POST request...");
|
|
res.writeHead(200, {'Content-Type': 'text/html'});
|
|
|
|
var body = '';
|
|
req.on('data', function (data) {
|
|
body += data;
|
|
});
|
|
req.on('end', function () {
|
|
console.log("POST payload: " + body);
|
|
res.end( body );
|
|
});
|
|
}
|
|
else
|
|
{
|
|
console.log("Handling GET request...");
|
|
res.writeHead(200, {'Content-Type': 'text/html'});
|
|
var html = '<html><body>HTTP Server at http://' + host + ':' + port + '</body></html>';
|
|
res.end(html);
|
|
}
|
|
|
|
});
|
|
|
|
server.listen(port, host);
|
|
console.log('Listening at http://' + host + ':' + port);
|