From 8641e98cbec47b83ee0ec9d031c2e179cac88f4e Mon Sep 17 00:00:00 2001 From: 0xYH <59072949+yulonghe97@users.noreply.github.com> Date: Thu, 15 Sep 2022 21:51:54 +0800 Subject: [PATCH] fixed the mismatched ports and urls under dev mode (#44) Co-authored-by: Detrainn --- src/commands/login/index.ts | 17 ++++++++++------- src/lib/urls.ts | 3 +-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/commands/login/index.ts b/src/commands/login/index.ts index 047ba4c..ded2c01 100644 --- a/src/commands/login/index.ts +++ b/src/commands/login/index.ts @@ -93,22 +93,25 @@ fastify.get("/complete", async (request: any, reply: any) => { const start = async () => { try { const ports = await portastic.find({ min: 8000, max: 8999 }); - const port = - process.env.NODE_ENV === "development" - ? 3000 - : ports[Math.floor(Math.random() * ports.length)]; - const localConsoleServer = getConsoleServer("local", port); + const port = ports[Math.floor(Math.random() * ports.length)]; // request a jwt from the console ui fastify.get("/", async (request, reply) => { console.log(`Sending user to ${consoleServer} to authenticate`); + + // the web dev server will be under port 3000, and api under port 3005 + const webServer = + process.env.NODE_ENV === "development" + ? getConsoleServer(3000) + : consoleServer + reply.redirect( - `${consoleServer}/login?returnUrl=http://127.0.0.1:${port}/token&clientId=${clientId}` + `${webServer}/login?returnUrl=http://0.0.0.0:${port}/token&clientId=${clientId}` ); }); fastify.listen({ port }).then(() => { - console.log(`Open Browser at http://127.0.0.1:${port} to complete login`); + console.log(`Open Browser at http://0.0.0.0:${port} to complete login`); }); } catch (err) { fastify.log.error(err); diff --git a/src/lib/urls.ts b/src/lib/urls.ts index 64657e8..a78f78b 100644 --- a/src/lib/urls.ts +++ b/src/lib/urls.ts @@ -1,6 +1,5 @@ // Console API Server export const getConsoleServer = ( - location: "local" | "remote" = "remote", port?: number ) => { const devMode = process.env.NODE_ENV === "development"; @@ -10,10 +9,10 @@ export const getConsoleServer = ( // WASI Repo Server export const getWASMRepoServer = ( - location: "local" | "remote" = "remote", port?: number ) => { const devMode = process.env.NODE_ENV === "development"; const host = devMode ? "http://0.0.0.0" : "https://wasi.bls.dev"; return `${host}:${port ? port : devMode ? 3006 : 443}`; }; +