Skip to content

Commit 642411e

Browse files
committed
feat(cli): support click-to-open on npmx.dev
1 parent aa79115 commit 642411e

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

app/composables/useConnector.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,23 @@ export const useConnector = createSharedComposable(function useConnector() {
6868

6969
const baseUrl = computed(() => `http://localhost:${config.value?.port ?? DEFAULT_PORT}`)
7070

71-
// Load persisted config on client
71+
const route = useRoute()
72+
const router = useRouter()
73+
7274
onMounted(() => {
75+
const urlToken = route.query.token as string | undefined
76+
const urlPort = route.query.port as string | undefined
77+
78+
if (urlToken) {
79+
const { token: _, port: __, ...cleanQuery } = route.query
80+
router.replace({ query: cleanQuery })
81+
82+
// Connect with URL params
83+
const port = urlPort ? Number.parseInt(urlPort, 10) : DEFAULT_PORT
84+
connect(urlToken, port)
85+
return
86+
}
87+
7388
const stored = localStorage.getItem(STORAGE_KEY)
7489
if (stored) {
7590
try {

cli/src/logger.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,15 @@ export function logMessage(message: string): void {
5858
* Show the connection token in a nice box
5959
*/
6060
export function showToken(token: string, port: number): void {
61+
const connectUrl = `https://npmx.dev/?token=${token}&port=${port}`
62+
6163
p.note(
6264
[
63-
`Token: ${pc.bold(pc.cyan(token))}`,
65+
`Open: ${pc.bold(pc.underline(pc.cyan(connectUrl)))}`,
6466
'',
65-
pc.dim(`Server: http://localhost:${port}`),
67+
pc.dim(`Or paste token manually: ${token}`),
6668
].join('\n'),
67-
'Paste this token in npmx.dev to connect',
69+
'Click to connect',
6870
)
6971
}
7072

0 commit comments

Comments
 (0)