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.
69 lines
1.6 KiB
69 lines
1.6 KiB
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(
|
|
`
|
|
<!DOCTYPE html>
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<title>${title}</title>
|
|
<style type="text/css">*{ font-family: sans-serif }</style>
|
|
</head>
|
|
<body>
|
|
${content}
|
|
<form method='post' action='/'>
|
|
<input type='text' value='valeur' name='param' />
|
|
<button type='submit'>aller !</button>
|
|
</form>
|
|
</body>
|
|
</html>
|
|
`
|
|
);
|
|
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);
|