Concepts
app:// and your frontend
Where your app's page comes from and how Kurogane serves it from disk.
Your app’s first page comes from a URL or from a directory. A directory is served under the app:// scheme without an HTTP server.
Two sources
| Call | Loads | The page’s origin |
|---|---|---|
App::url |
any URL, such as a dev server | the URL’s own origin |
App::new |
a directory on disk | app://app |
The page’s origin is your app’s own origin. Commands, events and streams answer it without an App::permit. See IPC.
The starters load the dev server in debug builds and the bundled frontend in release builds:
use kurogane::App;
fn main() {
#[cfg(debug_assertions)]
App::url("http://localhost:5173").run_or_exit();
#[cfg(not(debug_assertions))]
App::new("content").run_or_exit();
}
The app scheme
App::new("content") serves the content directory at app://app/. app://app and app://app/ both load its index.html.
The scheme behaves like an https origin. Pages under it are same-origin with each other and count as a secure context. fetch and CORS work as they do on the web. Nothing listens on a port.
Kurogane checks the directory before Chromium starts. A missing directory, a file in its place or a missing index.html fails startup with a RuntimeError that names the path.
What it serves
- A path names a file inside the directory. Its content type follows the file’s extension.
- Query strings and fragments don’t change which file is served.
- A path that names no file answers
404. There is no fallback toindex.html. Use hash-based routing for client-side routes. - A URL with a host other than
appanswers400.
What it never serves
A request resolves inside the directory and nowhere else:
- No
.., absolute path, drive letter or network path leaves it. - A link inside the directory is followed only while it stays inside.
- Anything outside answers the same
404as a missing file. A page can’t tell what exists beyond the directory.
Kurogane reads files on a worker thread. Reading a large asset doesn’t hold up the thread that carries IPC.
Relative directories in a bundle
A packaged app can’t rely on its working directory. macOS starts a .app from /. Windows and Linux start it from wherever it was launched.
A relative directory resolves against the bundle’s resource root instead:
| Platform | Executable | Resource root |
|---|---|---|
| Linux | <root>/runtime/<exe> |
<root> |
| Windows | <root>/<exe>.exe |
<root> |
| macOS | <name>.app/Contents/MacOS/<exe> |
<name>.app/Contents/Resources |
An absolute directory is never rebased. An unbundled run such as cargo run has no resource root. It resolves against the working directory.
resource_dir gives the resource root to reach other files a bundle carries:
let config = match kurogane::resource_dir() {
Some(resources) => resources.join("config.toml"),
None => std::path::PathBuf::from("config.toml"),
};
Your own schemes
App::register_scheme serves a scheme of your own from a SchemeHandler. It answers content that isn’t on disk or is computed per request:
use kurogane::tanso::{Browser, Frame, Request, ResourceHandler};
use kurogane::{App, SchemeHandler, resource_handler_from_bytes};
struct Greeting;
impl SchemeHandler for Greeting {
fn create(
&self,
_browser: Option<&mut Browser>,
_frame: Option<&mut Frame>,
_request: Option<&mut Request>,
) -> Option<ResourceHandler> {
Some(resource_handler_from_bytes(b"hello".to_vec(), "text/plain", 200))
}
}
fn main() {
App::new("content").register_scheme("greeting", Greeting).run_or_exit();
}
- Every request on the scheme reaches the handler whatever its host.
- Chromium calls
createon its IO thread. That thread also carries every IPC message. Decide there what to answer and leave slow work to the returned handler’sopenandread. Those run on a worker thread. - A panic in
createfails the request as returningNonedoes. - Your schemes behave like
appdoes. They’re standard, secure and allowfetchand CORS. - A page served from your scheme has that scheme’s origin. It reaches commands only once
App::permitnames it. appis reserved. A scheme name starts with a letter and holds letters, digits,+,-or.. An invalid or repeated name is a configuration error.
resource_handler_from_bytes answers with bytes already in memory. Implement ResourceHandler yourself for anything larger or slower.