feat(cli): add --allowed-host option for dev server#2971
Conversation
Adds repeatable `--allowed-host` to `likec4 start` (`serve`/`dev`) which threads through to Vite's `server.allowedHosts`. When omitted, all hosts continue to be allowed (current behaviour), so this is strictly additive. Drops the obsolete TODO comment block around `allowedHosts: true` in `vite-dev.ts` since users can now scope access down via the new flag. Resolves likec4#1650
🦋 Changeset detectedLatest commit: 14d64f2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 22 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughAdds a repeatable ChangesCLI Allowed-Host Option
Sequence DiagramsequenceDiagram
participant CLI as CLI args
participant Serve as serve command
participant Handler as handler()
participant ViteDev as viteDev()
participant Vite as Vite config
CLI->>Serve: --allowed-host example.com --allowed-host api.example.com
Serve->>Handler: { allowedHosts: ['example.com','api.example.com'] }
Handler->>ViteDev: allowedHosts: ['example.com','api.example.com']
ViteDev->>Vite: server.allowedHosts = ['example.com','api.example.com']
CLI->>Serve: (no --allowed-host)
Serve->>Handler: { allowedHosts: undefined }
Handler->>ViteDev: allowedHosts: undefined
ViteDev->>Vite: server.allowedHosts = true
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/likec4/src/cli/options.ts`:
- Around line 96-101: The allowedHost option is defined with array: true
(allowedHost) so yargs-parser's greedy-arrays can unintentionally capture the
trailing positional path; disable greedy arrays by adding parserConfiguration({
'greedy-arrays': false }) to the main yargs chain (the object that builds
options and calls parseAsync()) before calling parseAsync() so positional [path]
is not consumed as another allowedHost value.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e20b4405-b06b-42dc-b68c-6d6f274249ed
📒 Files selected for processing (7)
.changeset/cli-allowed-host-option.mdapps/docs/src/content/docs/tooling/cli.mdxpackages/likec4/src/cli/options.tspackages/likec4/src/cli/serve/index.tspackages/likec4/src/cli/serve/serve.spec.tspackages/likec4/src/cli/serve/serve.tspackages/likec4/src/vite/vite-dev.ts
… --allowed-host yargs-parser's default greedy-arrays would let `--allowed-host foo.com ./path` swallow `./path` into the array and silently fall back to the positional default. Disabling greedy-arrays enforces the documented repeat-flag usage. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
davydkov
left a comment
There was a problem hiding this comment.
@farhan523 Thanks for the PR! I agree with your "Out of scope" reasoning — let's keep allowedHosts: true as the default for now.
Changing it to "strictly defined" is a behaviour change that would break existing setups, so it's better keep it (for 1.x)
The additive approach here is exactly right: users who need to scope hosts down have a clean CLI surface, everyone else keeps working as-is.
Checklist
mainbefore creating this PR.pnpm typecheckandpnpm test.Summary
Resolves #1650.
Adds a repeatable
--allowed-hostoption tolikec4 start(aliasesserve/dev) which threads through to Vite'sserver.allowedHosts.Today,
vite-dev.tshardcodesallowedHosts: truewith a// TODO: temprorary enable access to any hostcomment from #1649. This PR keepstrueas the default (so existing behaviour is preserved and the change is strictly additive), and gives users a CLI surface to scope access down when they want it.Implementation
allowedHostoption inpackages/likec4/src/cli/options.ts(array: true,string: true,requiresArg: true).serve/index.ts→serve.tshandler →viteDev.vite-dev.ts, replaces the hardcodedallowedHosts: truewithallowedHosts && allowedHosts.length > 0 ? allowedHosts : true. The obsolete// TODO: temprorary…comment is removed since users now have a way to address this themselves.serve.spec.ts(with the hostnames + without — default branch).--allowed-hostrow to theserveoptions table inapps/docs/src/content/docs/tooling/cli.mdx.Out of scope
This PR does not change the default. The maintainer note in #1650 says "we should enable only strictly defined" — that's a behaviour change that probably deserves its own PR (and possibly a deprecation cycle), separate from adding the CLI surface. Happy to follow up if you'd like the default flipped here.
Test plan
New propagation tests:
servehandler propagatesallowedHostsarray toviteDevservehandler leavesallowedHostsundefined when not provided (preserves the "allow all" default)