# Capacitor and Tauri

A native shell (Capacitor for iOS and Android, Tauri for desktop) loads a folder of static files in a webview. That is the [`static`](/deploy/presets/static) preset: `hamur generate` writes `.output/public/`, and the shell packages it. The shell has no Hamur server, so everything that needs one is dropped or has to live elsewhere.

## Build the web part

Render every route in the browser, list the paths a user can open directly, and give the app the absolute URL of its API:

````ts [native-config.ts]
import { defineConfig } from "hamur"

export default defineConfig({
  framework: "react",
  ssr: false,
  prerender: { routes: ["/", "/settings"] },
  runtimeConfig: { public: { apiBase: "https://api.example.com" } },
  $development: { runtimeConfig: { public: { apiBase: "http://localhost:4000" } } },
})
````

- `ssr: false` sends the single-page shell for every route. A path in `prerender.routes` is written as full HTML, and every other path keeps the `200.html` shell. The shells load files and know nothing of `200.html`, so list each route a user can reload on.
- `hamur generate` builds the `static` preset: no function, no server routes. Server routes, `proxy`, `cors`, `swr` and `cache` rules and `server.fallbackProxy` are dropped, and the build warns with the list. Storage, sessions and server routes work during the build and nowhere after it. See [Static](/deploy/presets/static#output).
- A webview loads the app from its own origin, so `/api/...` points at the shell. Read the API from `useRuntimeConfig().public.apiBase`, set to an absolute URL, with a different value under `hamur dev` through `$development` as in the sample. See [Runtime config](/configuration#runtime-config).
- `app.baseURL` stays `/`.

The API app answers from another origin, so it needs a `cors` rule for the origins the shells use:

````ts [native-api-config.ts]
import { defineConfig } from "hamur"

export default defineConfig({
  framework: "react",
  routeRules: {
    "/api/**": {
      cors: {
        origin: ["capacitor://localhost", "http://localhost", "tauri://localhost", "http://tauri.localhost"],
        credentials: true,
      },
    },
  },
})
````

The origins are the ones the shells use: `capacitor://localhost` (iOS) and `http://localhost` (Android) for Capacitor, `tauri://localhost` (macOS and Linux) and `http://tauri.localhost` (Windows) for Tauri. Take them from the shell's documentation for the version you use.

## Capacitor

Point `webDir` at the output and copy it into the native projects after each build:

````json [capacitor.config.json]
{
  "appId": "com.example.app",
  "appName": "My app",
  "webDir": ".output/public"
}
````

````sh [native-build.sh]
hamur generate
npx cap sync
````

## Tauri

Tauri runs your commands around its own: `beforeDevCommand` starts `hamur dev` and the window loads `devUrl`; `beforeBuildCommand` runs `hamur generate` and the bundle packs `frontendDist`, relative to the folder of `tauri.conf.json`.

````json [tauri.conf.json]
{
  "productName": "my-app",
  "version": "0.1.0",
  "identifier": "com.example.app",
  "build": {
    "beforeDevCommand": "hamur dev",
    "devUrl": "http://localhost:3000",
    "beforeBuildCommand": "hamur generate",
    "frontendDist": "../.output/public"
  }
}
````

The `hamur dev` server listens on port 3000 unless you pass `--port` or set `devServer.port`; keep `devUrl` the same. These keys are the ones Tauri 2 documents; check them against the Tauri version you install.
