Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: option to show baseURL in showURL #28

Merged
merged 4 commits into from
Jun 13, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface Listener {
server: http.Server | https.Server,
close: () => Promise<void>,
open: () => Promise<void>,
showURL: () => void
showURL: (options?: Pick<ListenOptions, 'baseURL'>) => void
}

export async function listen (handle: http.RequestListener, opts: Partial<ListenOptions> = {}): Promise<Listener> {
Expand Down Expand Up @@ -109,13 +109,14 @@ export async function listen (handle: http.RequestListener, opts: Partial<Listen
await clipboardy.write(url).catch(() => { opts.clipboard = false })
}

const showURL = () => {
const showURL = (overrides?: Pick<ListenOptions, 'baseURL'>) => {
antfu marked this conversation as resolved.
Show resolved Hide resolved
const add = opts.clipboard ? gray('(copied to clipboard)') : ''
const lines = []
lines.push(` > Local: ${formatURL(url)} ${add}`)
const baseURL = (overrides?.baseURL || opts.baseURL || '').slice(1)
lines.push(` > Local: ${formatURL(url + baseURL)} ${add}`)
if (isExternal) {
for (const ip of getExternalIps()) {
lines.push(` > Network: ${formatURL(url.replace('localhost', ip))}`)
lines.push(` > Network: ${formatURL(url.replace('localhost', ip) + baseURL)}`)
}
}
// eslint-disable-next-line no-console
Expand Down