-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssr.js
30 lines (30 loc) · 842 Bytes
/
ssr.js
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
const http = require('http');
const fs = require('fs');
http.createServer(function (request, response) {
let url = request.url;
response.setHeader('Content-type', 'text/html;charset=UTF-8');
if (url === '/') {
response.end(`
<html>
<head>
<title>hello</title>
</head>
<body>
<h1 style="color: aqua; font-size: 25px;">hello</h1>
<p>world</p>
<button class="add">添加</button>
<script src="./index.js"></script>
</body>
</html>
`);
return;
}
if (url === '/index.js') {
response.setHeader('Content-type', 'text/x-javascript;charset=utf-8');
fs.readFile('.' + url, (err, str) => {
response.end(str);
});
return;
}
response.end('end');
}).listen(2233);