-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsimpleHTTP.js
More file actions
39 lines (35 loc) · 802 Bytes
/
simpleHTTP.js
File metadata and controls
39 lines (35 loc) · 802 Bytes
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
37
let http = require('http')
const PORT = 7000;
const HtmlTemplateString = (header,body,footer) => {
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
${header}
</head>
<body>
<h1>${body}</h1>
${footer}
</body>
</html>`;
}
let page1 =HtmlTemplateString(
`<title>Hello</title>`,
`<h1>Hello World END</h1>`,
`<footer> By Hans </footer>`)
http.createServer(
(request,res)=>{
if (request.url == '/') {
res.writeHead(200, {
'Content-Type': 'text/html',
'Content-Length': page1.length,
'Expires': new Date().toUTCString()
})
res.end(page1);
}
else {
return response.end('Invalid request');
}
}
).listen(PORT);