Azure Static Web Apps
--preset azure-swa is chosen when INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN is set, which the Static Web Apps deploy action passes to the build, or by name.
Reference
| Preset | azure-swa |
| Runs on | Azure Static Web Apps |
event.runtime.name | azure |
| Server target | node |
| Lifetime, startup | request, request |
Output
.output/
hamur.json
public/ the static files and staticwebapp.config.json
server/ the API, an Azure Functions v4 app: host.json, package.json, functions.mjs, index.mjs
Config keys
This preset has no key of its own.
Detection
The build selects it when INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN is set, unless --preset, preset or HAMUR_PRESET names another. It is a row of the one table of markers in Choosing a preset.
Deploy command
hamur deploy builds, then runs swa deploy .output/public --api-location .output/server --env production; with --preview it runs swa deploy .output/public --api-location .output/server --env preview. See hamur deploy. The preview command of the preset, which hamur preview runs or prints, is npx @azure/static-web-apps-cli start .output/public --api-location .output/server.
Limits
- Runs: private
app/env.tsentries read at run time. - Does not run: WebSockets and
server.syncedState,server.pubsub, streamed answers,server.metrics, image transforms at run time, Durable Object classes. tasks.runOnStartfails the build and rate limits count per instance;staticwebapp.config.jsonis at most 20 KB; the managed API runs Node 20 or 22.
The levels are the features of the preset: hamur build warns or fails when the app uses a feature the preset does not run (see Preset features).
.output/public/ the static files and staticwebapp.config.json
.output/server/ the API: host.json, package.json, functions.mjs, index.mjs
The server is an Azure Functions v4 app: functions.mjs registers one anonymous function, app.http("server", { route: "{*path}", ... }), and package.json names it as main and depends on @azure/functions. Static Web Apps fixes the managed API at /api, so the function answers under /api/, and staticwebapp.config.json sends every request that matches no file to it with navigationFallback: { "rewrite": "/api/server", "exclude": [] }. Static Web Apps tells the function the path the browser asked for in the x-ms-original-url header, and the function serves that path; a direct /api/... call without the header is served as it is.
The build merges your own staticwebapp.config.json (from public/ or the project root) with its keys. Everything in your file is kept and your routes come first, since Azure applies the first rule that matches. The build adds:
routesfor route rules:redirect(a literal target, with the rule's status, 307 by default),headersandnoindex, and/_hamur/*with the immutableCache-Control. A pattern whose*is not at the end of the path cannot be written; it is left out with a warning naming the rule, and so is a redirect whose target has a**or a:param. The function applies both of them to the requests it answers.globalHeaderswith the default security headers (your entries win). Static Web Apps does not add them to API answers, which already carry them.navigationFallbackunless your file has one, andplatform.apiRuntime: "node:22"unless your file sets it.
The file may be at most 20 KB; a larger one fails the build. The managed API runs Node 20 or 22, below Hamur's Node 24, so the build warns once: Azure Static Web Apps runs the API on Node 22, below Hamur's Node 24; the build targets Node 22 APIs only. The function buffers each answer, so streaming is not available.
npx @azure/static-web-apps-cli start .output/public --api-location .output/server
swa deploy .output/public --api-location .output/server
tasks.runOnStart fails the build and rate limits count per instance.