[CRA] Configure create-instant-app for self-hosted backends - #2803
Conversation
📝 WalkthroughWalkthroughProject base metadata is centralized and reused for CLI choices, environment files, bundled examples, and backend configuration. The CLI injects API and WebSocket settings into scaffolded JavaScript, TypeScript, or Python backends when ChangesProject base configuration
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant CLI
participant applyBackendConfig
participant projectBaseConfig
participant ScaffoldFiles
CLI->>applyBackendConfig: pass project base, project directory, and API URI
applyBackendConfig->>projectBaseConfig: read configured backend files
applyBackendConfig->>ScaffoldFiles: inject API and WebSocket configuration
ScaffoldFiles-->>CLI: persist updated scaffold files
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
|
View Vercel preview at instant-www-js-update-cra-self-host-jsv.vercel.app. |
drew-harris
left a comment
There was a problem hiding this comment.
Tested and working!
https://gist.github.com/drew-harris/16f6ba91dc8fc26a37f412d4b512fb35
ccf9bdc to
c73d2e2
Compare
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 `@client/packages/create-instant-app/src/index.ts`:
- Around line 48-54: Wrap the applyBackendConfig call guarded by
INSTANT_CLI_API_URI in error handling, catching malformed URI or
template-initializer failures. Surface a concise, user-facing error through the
existing CLI error mechanism, avoid the raw stack trace, and stop the scaffold
flow before continuing with subsequent setup steps.
🪄 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: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 56ed13f9-863a-449b-9c6c-02fcf136ef5f
📒 Files selected for processing (9)
client/packages/create-instant-app/scripts/copyExamples.tsclient/packages/create-instant-app/src/backendConfig.test.tsclient/packages/create-instant-app/src/backendConfig.tsclient/packages/create-instant-app/src/cli.tsclient/packages/create-instant-app/src/env.tsclient/packages/create-instant-app/src/index.tsclient/packages/create-instant-app/src/projectBase.tsclient/packages/create-instant-app/src/utils/getUserPkgManager.tsclient/packages/version/src/version.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- client/packages/create-instant-app/src/utils/getUserPkgManager.ts
| if (process.env.INSTANT_CLI_API_URI) { | ||
| applyBackendConfig( | ||
| project.base, | ||
| projectDir, | ||
| process.env.INSTANT_CLI_API_URI, | ||
| ); | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Uncaught applyBackendConfig failure crashes mid-scaffold, leaving a broken half-set-up project.
This call isn't wrapped in error handling. If INSTANT_CLI_API_URI is malformed, or a scaffolded file's expected initializer text (init({ / db = Instant()) doesn't match (e.g. future template drift), applyBackendConfig throws and the whole process dies with a raw stack trace — after projectDir already exists on disk but before rule files, env file, dependency install, package renaming, or git init have run.
🔧 Proposed fix: surface a clear, non-crashing error
if (process.env.INSTANT_CLI_API_URI) {
- applyBackendConfig(
- project.base,
- projectDir,
- process.env.INSTANT_CLI_API_URI,
- );
+ try {
+ applyBackendConfig(
+ project.base,
+ projectDir,
+ process.env.INSTANT_CLI_API_URI,
+ );
+ } catch (err) {
+ console.error(
+ `Warning: could not apply self-hosted backend config: ${
+ err instanceof Error ? err.message : err
+ }`,
+ );
+ console.error(
+ 'You may need to manually set apiURI/websocketURI in your backend init.',
+ );
+ }
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (process.env.INSTANT_CLI_API_URI) { | |
| applyBackendConfig( | |
| project.base, | |
| projectDir, | |
| process.env.INSTANT_CLI_API_URI, | |
| ); | |
| } | |
| if (process.env.INSTANT_CLI_API_URI) { | |
| try { | |
| applyBackendConfig( | |
| project.base, | |
| projectDir, | |
| process.env.INSTANT_CLI_API_URI, | |
| ); | |
| } catch (err) { | |
| console.error( | |
| `Warning: could not apply self-hosted backend config: ${ | |
| err instanceof Error ? err.message : err | |
| }`, | |
| ); | |
| console.error( | |
| 'You may need to manually set apiURI/websocketURI in your backend init.', | |
| ); | |
| } | |
| } |
🤖 Prompt for 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.
In `@client/packages/create-instant-app/src/index.ts` around lines 48 - 54, Wrap
the applyBackendConfig call guarded by INSTANT_CLI_API_URI in error handling,
catching malformed URI or template-initializer failures. Surface a concise,
user-facing error through the existing CLI error mechanism, avoid the raw stack
trace, and stop the scaffold flow before continuing with subsequent setup steps.
This PR does two things
Self-hosting
Previously,
INSTANT_CLI_API_URIpointedcreate-instant-appat a self-hosted backend, but generated apps still required manually addingapiURIandwebsocketURItoinit.Generated apps now include the self-hosted API and derived WebSocket configuration automatically.
Project bases
Consolidated duplicated project base declarations into one registry. CLI choices, environment variables, bundled templates, and backend configuration files now derive from the same source.