Skip to content

Commit

Permalink
Merge pull request #76 from macacajs/feat-global-proxy
Browse files Browse the repository at this point in the history
Feat global proxy
  • Loading branch information
zhangyuheng authored Aug 9, 2018
2 parents 4d730d7 + 1f93031 commit ac0d5b0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/controller/api/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ class InterfaceController extends Controller {
ctx.success(res);
}

async updateAllProxy() {
const ctx = this.ctx;
const { projectUniqId, enabled } = ctx.request.body;
const res = await ctx.service.interface.updateAllProxy({ projectUniqId, enabled });
ctx.success(res);
}

async delete() {
const ctx = this.ctx;
const { uniqId } = ctx.params;
Expand Down
1 change: 1 addition & 0 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module.exports = app => {
router.post('/api/sdk/switch_scene', controller.api.sdk.switchScene);
router.post('/api/sdk/switch_multi_scenes', controller.api.sdk.switchMultiScenes);
router.post('/api/sdk/switch_all_scenes', controller.api.sdk.switchAllScenes);
router.post('/api/sdk/switch_all_proxy', controller.api.interface.updateAllProxy);

router.all('/data/:projectName/:pathname+', contextMiddleWare, controller.data.index);
};
22 changes: 22 additions & 0 deletions app/service/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ class InterfaceService extends Service {
);
}

async updateAllProxy({ projectUniqId, enabled }) {
const interfaces = await this.ctx.model.Interface.findAll({
where: {
projectUniqId,
},
});

await Promise.all(interfaces.map(async item => {
const proxyConfig = Object.assign(item.proxyConfig, {
enabled,
});
return await this.updateInterface({
uniqId: item.dataValues.uniqId,
payload: {
proxyConfig,
},
});
}));

return null;
}

async deleteInterfaceByUniqId({ uniqId }) {
return await this.ctx.model.Interface.destroy({
where: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "macaca-datahub",
"version": "2.1.8",
"version": "2.1.9",
"description": "Continuous data provider for development, testing, staging and production.",
"bin": {
"datahub": "./bin/datahub.js",
Expand Down

0 comments on commit ac0d5b0

Please sign in to comment.