Make simulator API base configurable#1016
Conversation
Made-with: Cursor
✅ Deploy Preview for circuitverse ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
WalkthroughThis change introduces API base URL utilities in both the v0 and v1 simulator directories. Two new modules ( Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
v1/src/simulator/src/setup.js (1)
100-120:⚠️ Potential issue | 🟠 MajorKeep simulator-version redirects configurable too.
Line 117 and Line 120 still redirect to hard-coded absolute routes. That means a project load that switches simulator versions will bypass the new API-base configurability and still break when this app is mounted under a custom base path or paired with a different origin.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 471a3b3e-a02c-4c5f-976d-bfa3812bc016
📒 Files selected for processing (4)
src/simulator/src/apiBase.jssrc/simulator/src/setup.jsv1/src/simulator/src/apiBase.jsv1/src/simulator/src/setup.js

Fixes #1015
Describe the changes you have made in this PR -
src/simulator/src/apiBase.jsv1/src/simulator/src/apiBase.jswindow.CV_API_BASE(runtime override, no trailing slash)import.meta.env.VITE_API_BASE(build-time env, no trailing slash)/api(current CircuitVerse Rails default)fetchProjectDatain:src/simulator/src/setup.jsv1/src/simulator/src/setup.jsto use
buildApiUrl('/v1/projects/${projectId}/circuit_data')instead of a hard-coded/api/v1/...path.Screenshots of the UI changes (If any) -
N/A – no UI changes, only configuration / data-loading behavior.
Code Understanding and AI Usage
Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?
If you used AI assistance:
Explain your implementation approach:
/api/v1/projects/:id/circuit_data), which breaks when the simulator is hosted under a custom base path or on a different origin where the API is not available at/api.getApiBase+buildApiUrl) that first checks a runtime global (window.CV_API_BASE), then a build-time env variable (VITE_API_BASE), and finally falls back to/api. This keeps current production behavior while enabling route-agnostic and decoupled deployments.setup.jsbecause:setup.jsfocused on simulator setup and loading, not environment detection.getApiBase()returns the normalized API base URL (no trailing/), using the preference order above.buildApiUrl(path)joins the base with a given path fragment (with or without leading/), guaranteeing exactly one slash between them.fetchProjectData(projectId)in both v0 and v1 now usesbuildApiUrl('/v1/projects/${projectId}/circuit_data')so that all project-loading requests respect the configurable base.Checklist before requesting a review
I’d appreciate feedback on whether this approach aligns with the project's preferred configuration pattern.
Summary by CodeRabbit