feat: support env var substitution in API server URLs#80
Conversation
Resolve ${VAR} syntax in chronicle.yaml server URLs at runtime,
enabling single build deployed across multiple environments.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThis PR introduces environment variable substitution for OpenAPI server URLs. A new ChangesEnvironment Variable Substitution in API URLs
🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 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 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/chronicle/src/server/api/apis-proxy.ts`:
- Line 41: The code builds a resolved URL with
substituteEnvVars(spec.server.url) + path and later returns it in client-facing
errors (variable url), leaking env-derived values; change the error path to
avoid exposing the env-resolved URL by (1) retaining substituteEnvVars(...) for
internal requests but never interpolating that into client error strings, (2)
replace uses of url in responses with either the original spec.server.url
(unresolved) or a generic message like "Could not reach upstream service" and
(3) log the full resolved URL and error details only to server logs (e.g.,
inside the same function that calls substituteEnvVars/spec.server.url and
constructs url) while returning the sanitized message to clients; update
references to url and the error string in apis-proxy.ts accordingly.
In `@packages/chronicle/src/server/utils/api-markdown.ts`:
- Line 25: The call to substituteEnvVars inside the generateApiMarkdown
invocation can throw a raw Error for missing env vars; update the markdown route
so that any error from substituteEnvVars (or generateApiMarkdown) is caught and
re-thrown or returned as an instance of HTTPError (preserving message and status
like 400/422 as appropriate). Locate the code that calls
generateApiMarkdown(match.method, match.path, match.operation,
substituteEnvVars(...), match.spec.auth) and wrap the
substituteEnvVars/generateApiMarkdown call in a try/catch, and in the catch
create and throw a new HTTPError with the original error message (and suitable
HTTP status) so the route consistently returns HTTPError types.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a4459b15-0353-4cba-8080-a14fc9cfc987
📒 Files selected for processing (3)
packages/chronicle/src/lib/env.tspackages/chronicle/src/server/api/apis-proxy.tspackages/chronicle/src/server/utils/api-markdown.ts
Resolve ${VAR} in server.url via loadApiSpecs so resolved URL
flows to UI components, API proxy, md route, and /api/specs
endpoint from a single place.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
${VAR}env var substitution forserver.urlinchronicle.yamlAPI configloadApiSpecs— single place covers UI, API proxy,.mdroute, and/api/specsendpoint{domain}placeholder)server.urlvaluesUsage
Test plan
${VAR}and forwards requests to correct URL.mdroute resolves${VAR}in cURL snippets/api/specsreturns resolved URLs to client