-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (28 loc) · 956 Bytes
/
index.js
File metadata and controls
43 lines (28 loc) · 956 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
32
33
34
const rapAPIPrefixMap = {
1: 'rap.alibaba-inc.com/mockjsdata/',
2: 'rap2api.alibaba-inc.com/app/mock/'
}
const minimist = require('minimist')
const argv = minimist(process.argv.slice(2))
function rap(opts = {}) {
return function* rap(next) {
let rapVersion = opts.rapVersion || '2' //默认用rap2
let rapAPIPrefix = rapAPIPrefixMap[rapVersion]
//RAP项目id来自于命令行参数-i,其次取opts里的配置
const projectId = argv.i || opts.projectId || ''
this.isRap = true //标识现在是rap请求
this.rapProjectId = projectId
//rap2
if (rapVersion == '2') {
this.protocolAlias = 'https'
this.proxyPass = `${rapAPIPrefix + projectId}/${this.request.method}`
// this.request.method = 'GET'
this.isChangeOrigin = true //https需要设置header.host
} else {
//rap1
this.proxyPass = rapAPIPrefix + projectId
}
yield next
}
}
module.exports = rap