Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ Single:

```js
// {app_root}/config/config.default.js
exports.proxy = {
exports.eggProxy = {
host: 'http://localhost:9000', // target host that matched path will be proxy to
match: /\/assets/ // path pattern.
};
```
Multiple:
```js
// {app_root}/config/config.default.js
exports.proxy = [{
exports.eggProxy = [{
host: 'host1',
match: /\/assets1/
}, {
Expand Down
9 changes: 9 additions & 0 deletions README.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ exports.proxy = {

请到 [config/config.default.js](config/config.default.js) 查看详细配置项说明。

配置示例:
```js
// {app_root}/config/config.default.js
exports.eggProxy = {
host: 'http://localhost:9000', // 代理目标地址
match: /\/assets/ // 路径匹配规则
};
```

## 单元测试

<!-- 描述如何在单元测试中使用此插件,例如 schedule 如何触发。无则省略。-->
Expand Down
6 changes: 3 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict';

const proxy = require('koa-proxy');
const proxyMiddleware = require('koa-proxy');

module.exports = app => {
let proxyConfs = app.config.proxy || [];
let proxyConfs = app.config.eggProxy || [];
if (!Array.isArray(proxyConfs)) {
proxyConfs = [].concat(proxyConfs);
}

proxyConfs.forEach(config => {
app.use(proxy(config));
app.use(proxyMiddleware(config));
});
};
4 changes: 2 additions & 2 deletions config/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

/**
* egg-proxy default config
* @member Config#proxy
* @member Config#eggProxy
* @property {String} SOME_KEY - some description
*/

exports.proxy = {
exports.eggProxy = {
host: 'http://localhost:7001',
match: /^\/assets/,
};
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare module 'egg' {
interface EggAppConfig {
proxy: IProxy | IProxy[];
eggProxy: IProxy | IProxy[];
}
interface IProxy {
host?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports.keys = '123456';

exports.proxy = [
exports.eggProxy = [
{
host: 'http://127.0.0.1:1234',
match: /^\/proxy/,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports.keys = '123456';

exports.proxy = {
exports.eggProxy = {
host: 'http://127.0.0.1:1234',
match: /^\/proxy/,
};