Skip to content

Commit

Permalink
fixed the mismatched ports and urls under dev mode (#44)
Browse files Browse the repository at this point in the history
Co-authored-by: Detrainn <[email protected]>
  • Loading branch information
yulonghe97 and detrainn authored Sep 15, 2022
1 parent 3433957 commit 8641e98
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
17 changes: 10 additions & 7 deletions src/commands/login/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/lib/urls.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Console API Server
export const getConsoleServer = (
location: "local" | "remote" = "remote",
port?: number
) => {
const devMode = process.env.NODE_ENV === "development";
Expand All @@ -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}`;
};

0 comments on commit 8641e98

Please sign in to comment.