var http = require('http'); var url = require('url'); function outputHTML5(status, response, content, title) { response.writeHead(status, { 'Content-Type': 'text/html; charset=utf-8' }); response.write( ` ${title} ${content}
` ); response.end(); } var server = http.createServer(function (request, response) { if(request.url === "/") { parsedUrl = url.parse(request.url, true); if(request.method === "POST") { http.request ( "http://localhost:8080", { headers: {}, query : parsedUrl.query }, resp => { resp.on( 'data', function () { outputHTML5(200,response,"Info SENT","Bonjour"); } // eof response data )// eof on resp.on { 'error', function () { outputHTML5(200,response,"Info invalid","Bonjour"); } } } ); } else { outputHTML5(200,response,"Hello World!","Bonjour"); } } else { outputHTML5(404,response,'Y\'a rien ici',"Oups"); } }); server.listen(80);