Repository navigation
feat(cli): self-host runtime options for containers - #147
Merged
Merged
Conversation
`cloudhal studio --host <addr>` (CLOUDHAL_HOST) picks the address it listens on, `--base-url <url>` (CLOUDHAL_BASE_URL) the public origin for Better Auth's baseURL, the API's trusted origins and the printed URL, and `--behind-proxy` (CLOUDHAL_BEHIND_PROXY=1) makes `serveNode` take each request's scheme and host from X-Forwarded-Proto/Host (new `trustProxy`, `forwardedUrl`, `forwardedRequest` in @cloudhal/api/node). `--init-if-empty` (CLOUDHAL_INIT=<starter>) scaffolds the project through `init` when the folder has no cloudhal.json, so a container starts on an empty volume. `--host` now takes an address for `dev` too; alone it still means every interface. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Signed-off-by: Madraka <8898640+Madraka@users.noreply.github.com>
3 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Step 1 of #143 (self-host Docker image): the runtime options a container cannot do without.
cloudhal studio --host <addr>/CLOUDHAL_HOST: the address to listen on (serveNodekeeps127.0.0.1by default;0.0.0.0in a container).--hostalone still means every interface, fordevtoo (--host [<addr>];parseArgshas no optional values, so a bare flag is filled in before parsing).--base-url <url>/CLOUDHAL_BASE_URL: the public origin behind a reverse proxy. It becomes Better Auth'sbaseURL(session cookies are__Secure-/Securefor https), a trusted origin for the API's own CSRF check, and the URL the command prints. Origins only; a path is refused.--behind-proxy/CLOUDHAL_BEHIND_PROXY=1:serveNode's newtrustProxyrewrites each request to the scheme and host inX-Forwarded-Proto/X-Forwarded-Host(first value of a chain, validated), so everything derived fromc.req.url(CSRF and MCP origin checks, upload tickets, links) sees the public origin. Without the flag the headers are ignored, as before.forwardedUrl/forwardedRequestare exported from@cloudhal/api/node.--init-if-empty/CLOUDHAL_INIT=<starter>(with--starter,--name/CLOUDHAL_SITE_NAME): when the folder has nocloudhal.json,studiorunsinitfirst (reused, not duplicated), so a container starts on an empty/datavolume. A folder with other files is refused, asinitrefuses it.studio()returns the boundportnext tourl. New modulepackages/cli/src/commands/studio-options.tsholds the resolution (flags over environment) sostudio()stays within the function limit.Tests:
packages/cli/test/studio-selfhost.test.ts(option resolution, bare--host, first-run scaffold once, a proxied sign-up that gets aSecurecookie and passes the CSRF check while a foreign origin is refused) andpackages/api/test/node-proxy.test.ts(forwardedUrl,serveNodewith and withouttrustProxy, body passthrough).Checklist
pnpm lint,pnpm typecheck(api, cli),pnpm size:checkand the touched test files pass locally (the fullpnpm checkruns in CI)pnpm genwas run and generated files are committed (docs/adr/0001) — n/apnpm changesetaddedgit commit -s, DCO)cloudhal --help, which the docs site's CLI reference is generated from)🤖 Generated with Claude Code