Skip to content

Commit

Permalink
feat: 增强 http-proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
huangapple committed Dec 8, 2022
1 parent 74aa8a7 commit 8414f4b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/http-proxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,11 @@ export const httpProxy = {
host: 'http://127.0.0.1',
match: /\/assets\/(.*)/,
target: 'http://127.0.0.1/$1',

//额外的axios请求config, 会照搬过去
extReqOptions:{
//用来设置不校验https的ssl
httpsAgent: new https.Agent({ rejectUnauthorized: false })
}
}
```
2 changes: 2 additions & 0 deletions packages/http-proxy/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export interface HttpProxyStrategy {
ignoreHeaders?: {
[key: string]: boolean;
}
// 额外的axios请求config, 详情见 https://axios-http.com/docs/req_config
extReqOptions?: { [key: string]: any }
}

export interface HttpProxyConfig extends HttpProxyStrategy {
Expand Down
1 change: 1 addition & 0 deletions packages/http-proxy/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class HttpProxyMiddleware implements IMiddleware<any, any> {
const isStream = targetRes.on && targetRes.writable;

const reqOptions: any = {
...(this.httpProxy.extReqOptions || {}),
method,
url: url.href,
headers: reqHeaders,
Expand Down

0 comments on commit 8414f4b

Please sign in to comment.