Skip to content

Commit

Permalink
proxy server support update-ports restart command
Browse files Browse the repository at this point in the history
  • Loading branch information
jchip committed Mar 24, 2021
1 parent 44819a1 commit 45a2ab2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/xarc-app-dev/src/lib/dev-admin/admin-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ ${instruction}`
this._updateProxyTimer = null;
this.sendMsg(PROXY_SERVER_NAME, {
...update,
name: "restart",
name: "update-ports",
quiet: true
});
}, 250).unref();
Expand Down
39 changes: 32 additions & 7 deletions packages/xarc-app-dev/src/lib/dev-admin/redbird-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,38 @@ const registerElectrodeDevRules = ({
src: formUrl({ protocol, host, path: controlPaths.restart }),
target: `http://localhost:29999/skip`,
onRequest: (req, res) => {
const restartOpts = QS.parse(req._url.split("?")[1]);

res.statusCode = 200;
res.write(`proxy restarted`);
res.end();

process.nextTick(() => restart(restartOpts));
const restartOpts = { ...QS.parse(req._url.split("?")[1]) };

const newPorts: any = {};

if (restartOpts.updatePorts) {
if (restartOpts.hasOwnProperty("appPort")) {
const appPort = restartOpts.appPort as string;
if (appPort !== `${regAppPort}`) {
newPorts.appPort = appPort;
}
}
if (restartOpts.hasOwnProperty("webpackDevPort")) {
const webpackDevPort = restartOpts.webpackDevPort as string;
if (webpackDevPort !== `${regWebpackDevPort}`) {
newPorts.webpackDevPort = webpackDevPort;
}
}
res.statusCode = 200;
if (_.isEmpty(newPorts)) {
res.write(`update-ports - proxy ports same: app ${regAppPort}, wds ${regWebpackDevPort}`);
} else {
res.write(`update-ports - proxy proxy ports updated`);
process.nextTick(() => restart({ ...restartOpts, newPorts }));
}
res.end();
} else {
res.statusCode = 200;
res.write(`proxy restarted`);
res.end();

process.nextTick(() => restart({ ...restartOpts, newPorts }));
}

return false;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/xarc-app-dev/src/lib/dev-admin/redbird-spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ const handleRestart = type => {
process.on("message", data => {
if (data.name === "restart") {
restart(_.omit(data, "name"));
} else if (data.name === "update-ports") {
restart({ ..._.omit(data, "name"), updatePorts: true });
}
});
};
Expand Down

0 comments on commit 45a2ab2

Please sign in to comment.