Skip to content

Commit 0983604

Browse files
authored
feat(cli): set host with env variable (#163)
1 parent bf55ec9 commit 0983604

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
],
2828
"scripts": {
2929
"build": "tsdown",
30-
"dev": "node --experimental-strip-types src/cli.ts",
30+
"dev": "NPMX_CLI_DEV=true node --experimental-strip-types src/cli.ts",
3131
"test:types": "tsc --noEmit"
3232
},
3333
"dependencies": {

cli/src/cli.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { getNpmUser } from './npm-client.ts'
1010
import { initLogger, showToken, logInfo, logWarning, logError } from './logger.ts'
1111

1212
const DEFAULT_PORT = 31415
13+
const DEFAULT_FRONTEND_URL = 'https://npmx.dev/'
14+
const DEV_FRONTEND_URL = 'http://localhost:3000/'
1315

1416
async function runNpmLogin(): Promise<boolean> {
1517
return new Promise(resolve => {
@@ -43,6 +45,8 @@ const main = defineCommand({
4345
},
4446
async run({ args }) {
4547
const port = Number.parseInt(args.port as string, 10) || DEFAULT_PORT
48+
const frontendUrl =
49+
process.env.NPMX_CLI_DEV === 'true' ? DEV_FRONTEND_URL : DEFAULT_FRONTEND_URL
4650

4751
initLogger()
4852

@@ -90,7 +94,7 @@ const main = defineCommand({
9094
logInfo(`Authenticated as: ${npmUser}`)
9195

9296
const token = generateToken()
93-
showToken(token, port)
97+
showToken(token, port, frontendUrl)
9498

9599
const app = createConnectorApp(token)
96100

cli/src/logger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ export function logMessage(message: string): void {
6363
/**
6464
* Show the connection token in a nice box
6565
*/
66-
export function showToken(token: string, port: number): void {
67-
const connectUrl = `https://npmx.dev/?token=${token}&port=${port}`
66+
export function showToken(token: string, port: number, frontendUrl: string): void {
67+
const connectUrl = `${frontendUrl}?token=${token}&port=${port}`
6868

6969
p.note(
7070
[

0 commit comments

Comments
 (0)