fix(lite): add lite:// protocol to serve local content#13644
Conversation
There was a problem hiding this comment.
Pull request overview
Introduces a custom lite:// protocol in the Lite Electron app so the packaged UI can be served through a secure, router-friendly origin (fixing reloads on client-side routes and avoiding file://).
Changes:
- Switch Vite build
baseto/so asset URLs work from a custom protocol origin. - Register a privileged
lite://appscheme and route requests to the bundled UI (servingindex.htmlfor route-like paths). - Load the main window via
lite://app/instead ofloadFile(...).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| apps/lite/ui/vite.config.ts | Adjusts Vite base path to support asset loading from the custom protocol origin. |
| apps/lite/electron/src/main.ts | Adds lite:// protocol registration/handler and switches the window load target to lite://app/. |
fa75739 to
6a98e04
Compare
6a98e04 to
67d9be7
Compare
| }), | ||
| ], | ||
| base: "./", | ||
| base: "/", |
There was a problem hiding this comment.
This change is necessary as, otherwise, when you reload e.g. on the route /project/<id>/workspace, assets are fetched relative to that (e.g. /project/<id>/workspace/assets/blabla.css).
I introduced this relative behavior in the first place as it was necessary when serving via file://, since the "ui root" does not correspond to the actual root of the app. But now with the lite:// protocol we want to have fetches be absolute, and then we direct them to the correct subdirectory as necessary.
When opening a project in the packaged app, React Router sets the path to /project/<id>/workspace. As we used to serve via the `file://` protocol, this made the effective `location.href` `file://project/<id>/workspace`. When reloading the page, Electron just requests whatever is set in the location. As that file does not exist, we fail the reload. This commit fixes that by introducing a custom `lite://` protocol where we simply serve the index file for any route-looking path, and let the router handle the rest. This also plugs a security hole inherent in serving local files via the `file://` protocol, see https://www.electronjs.org/docs/latest/tutorial/security#18-avoid-usage-of-the-file-protocol-and-prefer-usage-of-custom-protocols
2cd5241 to
8074123
Compare
When opening a project in the packaged app, React Router sets the path to
/project/<id>/workspace. As we used to serve via thefile://protocol, this made the effectivelocation.hreffile:///project/<id>/workspace. When reloading the page, Electron just requests whatever is set in the location. As that file does not exist, we fail the reload.This commit fixes that by introducing a custom
lite://protocol where we simply serve the index file for any route-looking path, and let the router handle the rest.This also plugs a security hole inherent in serving local files via the
file://protocol, see https://www.electronjs.org/docs/latest/tutorial/security#18-avoid-usage-of-the-file-protocol-and-prefer-usage-of-custom-protocols