WME/aufgabe5/node_modules/csvtojson/v1/interfaces/web/webServer.js

24 lines
827 B
JavaScript
Raw Normal View History

2019-01-09 11:25:28 +00:00
var http = require("http");
var Converter = require("../../core/Converter.js");
function startWebServer (args) {
args = args || {};
var serverArgs = {
port: args.port || '8801',
urlpath: args.urlpath || '/parseCSV'
};
var server = http.createServer();
server.on("request", function(req, res){
if (req.url === serverArgs.urlpath && req.method === "POST"){
req.pipe(new Converter({constructResult:false})).pipe(res);
} else {
res.end("Please post data to: " + serverArgs.urlpath);
}
});
server.listen(serverArgs.port);
console.log("CSV Web Server Listen On:" + serverArgs.port);
console.log("POST to " + serverArgs.urlpath + " with CSV data to get parsed.");
return server;
}
module.exports.startWebServer = startWebServer;