Skip to content

Commit ac0d5b0

Browse files
authored
Merge pull request #76 from macacajs/feat-global-proxy
Feat global proxy
2 parents 4d730d7 + 1f93031 commit ac0d5b0

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

app/controller/api/interface.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ class InterfaceController extends Controller {
5050
ctx.success(res);
5151
}
5252

53+
async updateAllProxy() {
54+
const ctx = this.ctx;
55+
const { projectUniqId, enabled } = ctx.request.body;
56+
const res = await ctx.service.interface.updateAllProxy({ projectUniqId, enabled });
57+
ctx.success(res);
58+
}
59+
5360
async delete() {
5461
const ctx = this.ctx;
5562
const { uniqId } = ctx.params;

app/router.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ module.exports = app => {
4848
router.post('/api/sdk/switch_scene', controller.api.sdk.switchScene);
4949
router.post('/api/sdk/switch_multi_scenes', controller.api.sdk.switchMultiScenes);
5050
router.post('/api/sdk/switch_all_scenes', controller.api.sdk.switchAllScenes);
51+
router.post('/api/sdk/switch_all_proxy', controller.api.interface.updateAllProxy);
5152

5253
router.all('/data/:projectName/:pathname+', contextMiddleWare, controller.data.index);
5354
};

app/service/interface.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,28 @@ class InterfaceService extends Service {
9090
);
9191
}
9292

93+
async updateAllProxy({ projectUniqId, enabled }) {
94+
const interfaces = await this.ctx.model.Interface.findAll({
95+
where: {
96+
projectUniqId,
97+
},
98+
});
99+
100+
await Promise.all(interfaces.map(async item => {
101+
const proxyConfig = Object.assign(item.proxyConfig, {
102+
enabled,
103+
});
104+
return await this.updateInterface({
105+
uniqId: item.dataValues.uniqId,
106+
payload: {
107+
proxyConfig,
108+
},
109+
});
110+
}));
111+
112+
return null;
113+
}
114+
93115
async deleteInterfaceByUniqId({ uniqId }) {
94116
return await this.ctx.model.Interface.destroy({
95117
where: {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "macaca-datahub",
3-
"version": "2.1.8",
3+
"version": "2.1.9",
44
"description": "Continuous data provider for development, testing, staging and production.",
55
"bin": {
66
"datahub": "./bin/datahub.js",

0 commit comments

Comments
 (0)