nsarrazin commited on
Commit
f6a70cc
·
1 Parent(s): 13e6f2c

feat: improve port detection on admin cli login

Browse files
Files changed (1) hide show
  1. src/lib/server/adminToken.ts +16 -2
src/lib/server/adminToken.ts CHANGED
@@ -38,9 +38,23 @@ class AdminTokenManager {
38
  // if admin token is set, don't display it
39
  if (!this.enabled || env.ADMIN_TOKEN) return;
40
 
41
- const port = import.meta.env.PORT ?? 5173;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  const url = (PUBLIC_ORIGIN || `http://localhost:${port}`) + "?token=";
43
- logger.info(`[ADMIN] You can login with ${url + this.token} on port ${port}.`);
44
  }
45
  }
46
 
 
38
  // if admin token is set, don't display it
39
  if (!this.enabled || env.ADMIN_TOKEN) return;
40
 
41
+ let port = process.argv.includes("--port")
42
+ ? parseInt(process.argv[process.argv.indexOf("--port") + 1])
43
+ : undefined;
44
+
45
+ if (!port) {
46
+ const mode = process.argv.find((arg) => arg === "preview" || arg === "dev");
47
+ if (mode === "preview") {
48
+ port = 4173;
49
+ } else if (mode === "dev") {
50
+ port = 5173;
51
+ } else {
52
+ port = 3000;
53
+ }
54
+ }
55
+
56
  const url = (PUBLIC_ORIGIN || `http://localhost:${port}`) + "?token=";
57
+ logger.info(`[ADMIN] You can login with ${url + this.token}`);
58
  }
59
  }
60