-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha_server.js
47 lines (42 loc) · 1.16 KB
/
a_server.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* @Author: zry
* @Date: 2021-03-30 15:53:16
* @LastEditors: zry
* @LastEditTime: 2021-03-31 14:50:10
* @Description:
*/
const app = require('http'),
dir = require('fs');
app.createServer((request, response) => (
response.writeHead(200, {'Content-Type': 'text/plain'}),
// 发送响应数据 "Hello World"
response.end('ttttttt'))
).listen(5656)
/****阻塞代码***/
let file = dir.readFileSync('./app/html/index.html');
console.log(file.toString())
/*****非阻塞代码
* 读取public代码
*/
dir.readFile('./src/public.js', function(err, data) {
if (err) return console.error(err);
console.log(data.toString());
})
console.log(123456789);
app.createServer((req, res) => {
let path = req.url.replace(/\/?(?:\?.*)?$/, '').toLowerCase();
switch (path) {
case '':
res.writeHead(200, {'Content-Type': 'text/plain'})
res.end('200空')
break;
case '/index':
res.writeHead(200, {'Content-Type': 'utf-8'})
res.end('index页面')
break;
default:
res.writeHead(404, {'Content-Type': 'text/plain'})
res.end('页面飞走了')
break;
}
}).listen(5555)