-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpress_demo3.js
71 lines (58 loc) · 1.61 KB
/
express_demo3.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
59
60
61
62
63
64
65
66
67
68
69
70
71
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var urlencodeParser = bodyParser.urlencoded({extend: false});
app.use(express.static('public'));
//get请求
app.get('/', function(req,res){
console.log("主页Get请求");
res.send('Hello Get');
})
//post请求
app.post('/',function(req,res){
console.log("主页Post请求");
res.send('Hello Post');
})
// /del_user 页面响应
app.delete('/del_user', function(req,res){
console.log("/del_user 响应delete请求");
res.send('删除页面');
})
// /list_user 页面get请求
app.get('/list_user', function(req,res){
console.log("/list_user get请求");
res.send('用户列表页面');
})
app.get('/ab*cd', function(req,res){
console.log("/ab*cd get请求");
res.send('正则匹配');
})
app.get('/index.html', function(req,res){
res.sendFile(__dirname + "/" + "index.html");
})
app.get('/demo.html', function(req,res){
res.sendFile(__dirname + "/" + "demo.html");
})
app.get('/process_get', function(req,res){
//输出json格式
response = {
first_name: req.query.first_name1,
last_name: req.query.last_name1
};
console.log(response);
res.end(JSON.stringify(response));
})
app.post('/process_post', urlencodeParser, function(req,res){
//输出json格式
response = {
first_name: req.body.first_name,
last_name: req.body.last_name
};
console.log(response);
res.end(JSON.stringify(response));
})
var server = app.listen(8081, function(){
var host = server.address().address;
var port = server.address().port;
console.log("应用实例,访问地址为:http://%s:%s",host,port);
})