Skip to content

feat(cli): add --target-host flag for dev servers not on localhost - #33

Open
bluzername wants to merge 1 commit into
0xnyn:mainfrom
bluzername:feat/target-host-flag
Open

bluzername wants to merge 1 commit into
0xnyn:mainfrom
bluzername:feat/target-host-flag

Conversation

@bluzername

Copy link
Copy Markdown

Closes #21.

What this do

Add a --target-host <hostname> flag so airship can proxy a dev server
that is not on localhost - for example a local subdomain like
app.mylocalapp.com, which is what the issue ask for.

The server package already had a targetHost option waiting inside
(packages/server/src/index.ts), it just was never wire up from the
CLI. This PR:

  • add the flag to the flag registry (args.ts), with same hostname
    validation --host already use
  • parse and validate it in toServeOptions
  • use it when checking the target port is really listening, both for
    an explicit --target and for the auto-detect path (before this it
    was hardcoded to check localhost even when a different host was
    given, so the "nothing is listening" error would be wrong)
  • pass it to startServer
  • show it in the launch banner and --json output, instead of always
    printing localhost in the "proxying your dev server at..." line
    even when that is not true anymore

Not touching --exec: when airship start the dev server itself it is
always a local child process, so that path keeps checking localhost
on purpose.

Test plan

  • New tests in apps/cli/src/commands/serve.test.ts
    (toServeOptions - target host) for the validation.
  • New tests in apps/cli/src/lib/banner.test.ts (launchBanner) that
    check the proxying line names the custom host, and still say
    localhost by default.
  • pnpm typecheck and pnpm turbo run test --filter=@airshiplabs/cli
    both green, 181 tests passed (176 before, +5 new).
  • Manual check: ran ./airship --target-host localhost --target 8199 --json against a real python3 -m http.server 8199, got back
    "targetHost": "localhost" in the JSON and the right proxy URL.
    Also checked the error path with a host nothing is listening on -
    message correctly names that host instead of localhost.
  • node scripts/sync-readme.mjs --check passes (README table updated,
    apps/cli/README.md regenerated).

I am not a collaborator here, just opening this for review, no rush.

…ocalhost

Issue 0xnyn#21: user run local app on a subdomain like app.mylocalapp.com
instead of localhost, and airship have no way to point at it. Server
package already had a targetHost option inside, but CLI never expose it.

This add a --target-host <hostname> flag, same validation as --host.
It is used when we check the target is really listening (before it was
always checking localhost even if user give different host), and it is
passed to startServer so proxy forward to right place. Launch banner
and --json output also show it now, so it not silently still say
"localhost" when it is not true anymore.

Test: new toServeOptions tests for target-host validation, and new
launchBanner tests that check the proxying line names the custom host.
Also test by hand with a real http.server on 127.0.0.1 with
--target-host localhost, and with a host nothing listen on, to see the
error message name the right host.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add target host option

1 participant