Add Tauri local API sidecar and desktop runtime routing with cloud fallback#46
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 55189242bd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!url.startsWith('/api/')) { | ||
| return nativeFetch(input, init); |
There was a problem hiding this comment.
Handle absolute /api URLs in desktop fetch patch
installRuntimeFetchPatch() only applies local→cloud retry logic when url.startsWith('/api/'), but desktop callers that go through proxyUrl()/toRuntimeUrl() issue absolute URLs like http://127.0.0.1:46123/api/... and therefore skip this branch. In the exact scenario this change is meant to cover (sidecar not running, e.g. node missing or launch failure), those requests fail outright instead of falling back to cloud, so panels using fetchWithProxy lose data in desktop mode.
Useful? React with 👍 / 👎.
| body, | ||
| }); | ||
|
|
||
| return await mod.default(request); |
There was a problem hiding this comment.
Fall back to cloud on local handler error responses
The sidecar only proxies to cloud when the handler throws, but it returns local non-OK responses directly (return await mod.default(request)). Several existing API handlers intentionally return 4xx/5xx when local secrets are missing (for example Groq-backed endpoints return 503), which means desktop users without those env vars get hard failures even though cloud fallback is available. This breaks the stated “local execution with cloud fallback” behavior for common endpoints.
Useful? React with 👍 / 👎.
7be050c
into
codex/add-tauri-v2-integration-and-configuration
…llback (koala73#46) ### Motivation - Provide a local backend for the Tauri desktop app so core functionality (news, summarization, markets, telemetry, status) does not require Vercel edge functions and can run offline or with reduced cloud dependency. - Minimize frontend changes by exposing the same `/api/*` paths locally and failing over to the cloud when handlers are missing or local execution fails. ### Description - Add a Node sidecar local API server at `src-tauri/sidecar/local-api-server.mjs` that dispatches `/api/*` to existing `api/*.js` handlers when present and proxies to the cloud (`https://worldmonitor.app`) as a fallback. - Start/stop the sidecar with the Tauri app lifecycle by launching it from `src-tauri/src/main.rs` and managing the child process state. - Update Tauri configuration in `src-tauri/tauri.conf.json` to allow the local API origin (`http://127.0.0.1:46123`) in the CSP and to include `../api` and `sidecar/local-api-server.mjs` as bundle resources. - Desktop runtime routing changes in `src/services/runtime.ts`: default desktop API base set to `http://127.0.0.1:46123`, added `getRemoteApiBaseUrl()` and an `installRuntimeFetchPatch()` function that patches `fetch` to route `/api/*` to the local sidecar with automatic cloud fallback. - Enable the runtime fetch patch at app start by calling `installRuntimeFetchPatch()` from `src/main.ts`. - Update `ServiceStatusPanel` (`src/components/ServiceStatusPanel.ts`) to render local backend status and to show clear messaging when the local backend is unavailable and the UI is using the cloud fallback. - Add documentation `docs/local-backend-audit.md` listing prioritized `/api/*` endpoints for desktop parity and describing the localization strategy. - Minor formatting run via `cargo fmt` adjusted `src-tauri/build.rs`. ### Testing - `npm run typecheck` (`tsc --noEmit`) passed successfully. - `cargo fmt` completed successfully and reformatted `src-tauri/build.rs` where needed. - `cargo check` failed in this environment due to network restrictions while downloading crates index (environment-specific HTTP 403); this is unrelated to the code changes themselves. - Local sidecar smoke tests (automated invocation): launched `node src-tauri/sidecar/local-api-server.mjs` and verified `GET /api/local-status` and `GET /api/service-status` returned expected JSON responses (local status included), demonstrating the sidecar dispatch and health endpoints work in this environment. - Playwright screenshot attempt failed because the dev server was not reachable from the test environment (`net::ERR_EMPTY_RESPONSE`), so UI screenshot validation could not be completed here. ------ [Codex Task](https://chatgpt.com/codex/tasks/task_e_698ead50f548833398717fa3b8c92230)
Motivation
/api/*paths locally and failing over to the cloud when handlers are missing or local execution fails.Description
src-tauri/sidecar/local-api-server.mjsthat dispatches/api/*to existingapi/*.jshandlers when present and proxies to the cloud (https://worldmonitor.app) as a fallback.src-tauri/src/main.rsand managing the child process state.src-tauri/tauri.conf.jsonto allow the local API origin (http://127.0.0.1:46123) in the CSP and to include../apiandsidecar/local-api-server.mjsas bundle resources.src/services/runtime.ts: default desktop API base set tohttp://127.0.0.1:46123, addedgetRemoteApiBaseUrl()and aninstallRuntimeFetchPatch()function that patchesfetchto route/api/*to the local sidecar with automatic cloud fallback.installRuntimeFetchPatch()fromsrc/main.ts.ServiceStatusPanel(src/components/ServiceStatusPanel.ts) to render local backend status and to show clear messaging when the local backend is unavailable and the UI is using the cloud fallback.docs/local-backend-audit.mdlisting prioritized/api/*endpoints for desktop parity and describing the localization strategy.cargo fmtadjustedsrc-tauri/build.rs.Testing
npm run typecheck(tsc --noEmit) passed successfully.cargo fmtcompleted successfully and reformattedsrc-tauri/build.rswhere needed.cargo checkfailed in this environment due to network restrictions while downloading crates index (environment-specific HTTP 403); this is unrelated to the code changes themselves.node src-tauri/sidecar/local-api-server.mjsand verifiedGET /api/local-statusandGET /api/service-statusreturned expected JSON responses (local status included), demonstrating the sidecar dispatch and health endpoints work in this environment.net::ERR_EMPTY_RESPONSE), so UI screenshot validation could not be completed here.Codex Task