-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (27 loc) · 739 Bytes
/
index.js
File metadata and controls
31 lines (27 loc) · 739 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
const express = require('express')
const app = express()
const proxer = require('../../src/index').proxyMiddleware
const static = require('../../src/index').staticMiddleware
/**
* 这个例子是展示基于插件编写的express中间件使用方法
*/
app.use(static({
rootPath: '../../'
}))
app.use(proxer({
target: 'http://localhost:4000',
hooks: {
proxyRequest(proxyReq, opt) {
proxyReq.setHeader('whoami', 'AlanChen')
// console.log(opt)
console.log('请求被拦截啦')
},
proxyError(err, from) {
console.log(err)
console.log(from)
}
}
}))
app.listen(3000, () => {
console.log('server is running at port 3000')
})