-
Notifications
You must be signed in to change notification settings - Fork 33
/
http.js
58 lines (57 loc) · 1.51 KB
/
http.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
48
49
50
51
52
53
54
55
56
57
58
//node.js 创建服务器需要用到http的模块
//创建服务器
var http = require('http');
//处理url
var url = require('url');
//处理字符串
var querystring = require('querystring');
//创建服务器
var app = http.createServer((request, response) => {
//request 请求头
//response 响应头
//把url上带的参数,也就是键值对拿到这里处理
console.log(url.parse(request.url).query);
//url处理完后的结果
var paramStr = url.parse(request.url).query;
//就是把url拿下来的键值对转化成js可用的对象
var param = querystring.parse(paramStr);
console.log("name:" + param.name)
console.log("callback:" + param.callback)
var obj = {
hotel: [{
'main1': '酒店',
'main2': '海外酒店',
'main21': '特价酒店',
'main3': '团购',
'main31': '民宿·客栈',
'switch': false
}, {
'main1': '酒店',
'main2': '海外酒店',
'main21': '特价酒店',
'main3': '团购',
'main31': '民宿·客栈',
'switch': false
}, {
'main1': '酒店',
'main2': '海外酒店',
'main21': '特价酒店',
'main3': '团购',
'main31': '民宿·客栈',
'switch': false
}, {
'main1': '酒店',
'main2': '海外酒店',
'main21': '特价酒店',
'main3': '团购',
'main31': '民宿·客栈',
'switch': true
}],
name: param.name
}
//返回信息
response.end(param.callback + "(" + JSON.stringify(obj) + ")")
})
//监听8888端口
app.listen(8888);
console.log("启动服务器")