Azure
Deploy Nitro apps to Azure Static Web Apps.
#Azure Static Web Apps
Preset: azure_swa
Note
Integration with this provider is possible with zero configuration.
Azure Static Web Apps are designed to be deployed continuously in a GitHub Actions workflow. Nitro detects this deployment environment and enables the azure_swa preset automatically.
The server is deployed as a managed Azure Function using the Node.js v4 programming model. This requires @azure/functions v4 in your project dependencies (Nitro offers to install it if it is missing). It is traced into the build output, so it does not need to be installed again during deployment.
npm i @azure/functions@^4Note
If you have @azure/functions v3 installed, upgrade it to v4. Version 3 uses the legacy programming model (function.json) and is no longer supported by this preset.
#Local preview
To test locally, install Azure Functions Core Tools, then build and start a local preview environment:
NITRO_PRESET=azure_swa npm run build
npx @azure/static-web-apps-cli start .output/public --api-location .output/server#Configuration
Azure Static Web Apps are configured using the staticwebapp.config.json file.
Nitro automatically generates this configuration file whenever the application is built with the azure_swa preset.
Nitro sets the following properties automatically:
| Property | Criteria | Default |
|---|---|---|
| platform.apiRuntime | Set to node:20 or node:22 based on the engines.node field in your package.json. | node:22 |
| navigationFallback.rewrite | Always /api/server | /api/server |
| routes | All prerendered routes are added. Additionally, if you do not have an index.html file, an empty one is created for compatibility purposes, and requests to /index.html are redirected to the root directory (handled by /api/server). | [] |
#Custom configuration
You can alter the Nitro-generated configuration using the azure.config option.
Custom routes are added and matched first. In case of a conflict (two objects with the same route property), custom routes override generated ones.
#Deploy from CI/CD via GitHub Actions
When you link your GitHub repository to Azure Static Web Apps, a workflow file is added to the repository.
When you are asked to select your framework, select custom and provide the following information:
| Input | Value |
|---|---|
| app_location | '/' |
| api_location | '.output/server' |
| output_location | '.output/public' |
If you miss this step, you can always find the build configuration section in your workflow and update the build configuration:
###### Repository/Build Configurations ######
app_location: '/'
api_location: '.output/server'
output_location: '.output/public'
###### End of Repository/Build Configurations ######That's it! Now Azure Static Web Apps will automatically deploy your Nitro-powered application on push.
If you are using runtimeConfig, you will likely want to configure the corresponding environment variables on Azure.