Azure

Azure Static Web Apps

Preset: azure (switch to this preset)

Zero Config Provider

Integration with this provider is possible with zero configuration. (Learn More)

Azure Static Web Apps are designed to be deployed continuously in a GitHub Actions workflow. By default, Nitro will detect this deployment environment and enable the azure preset.

Local preview

You can invoke a development environment to preview before deploying.

  1. NITRO_PRESET=azure yarn build
  2. npx @azure/static-web-apps-cli start .output/public --api-location .output/server

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:

InputValue
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:

  1. # .github/workflows/azure-static-web-apps-<RANDOM_NAME>.yml
  2. ###### Repository/Build Configurations ######
  3. app_location: '/'
  4. api_location: '.output/server'
  5. output_location: '.output/public'
  6. ###### End of Repository/Build Configurations ######

Note: Pending an update in the Azure Static Web Apps workflow, you will also need to run the following in your root directory:

  1. mkdir -p .output/server
  2. touch .output/server/.gitkeep
  3. git add -f .output/server/.gitkeep

That’s it! Now Azure Static Web Apps will automatically deploy your Nitro-powered application on push.

Azure Functions

Preset: azure-functions

Note: If you encounter any issues, please ensure you’re using a Node.js 14+ runtime. You can find more information about how to set the Node version in the Azure docs.

Local preview

Install Azure Functions Core Tools if you want to test locally.

You can invoke a development environment from the serverless directory.

  1. NITRO_PRESET=azure-functions yarn build
  2. cd .output
  3. func start

You can now visit http://localhost:7071/ in your browser and browse your site running locally on Azure Functions.

Deploy from your local machine

To deploy, just run the following command:

  1. # To publish the bundled zip file
  2. az functionapp deployment source config-zip -g <resource-group> -n <app-name> --src dist/deploy.zip
  3. # Alternatively you can publish from source
  4. cd dist && func azure functionapp publish --javascript <app-name>

Deploy from CI/CD via GitHub Actions

First, obtain your Azure Functions Publish Profile and add it as a secret to your GitHub repository settings following these instructions.

Then create the following file as a workflow:

  1. # .github/workflows/azure.yml
  2. name: azure
  3. on:
  4. push:
  5. branches:
  6. - main
  7. pull_request:
  8. branches:
  9. - main
  10. jobs:
  11. deploy:
  12. runs-on: ${{ matrix.os }}
  13. strategy:
  14. matrix:
  15. os: [ ubuntu-latest ]
  16. node: [ 14 ]
  17. steps:
  18. - uses: actions/setup-node@v2
  19. with:
  20. node-version: ${{ matrix.node }}
  21. - name: Checkout
  22. uses: actions/checkout@master
  23. - name: Get yarn cache directory path
  24. id: yarn-cache-dir-path
  25. run: echo "::set-output name=dir::$(yarn cache dir)"
  26. - uses: actions/cache@v2
  27. id: yarn-cache
  28. with:
  29. path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
  30. key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
  31. restore-keys: |
  32. ${{ runner.os }}-yarn-azure
  33. - name: Install Dependencies
  34. if: steps.cache.outputs.cache-hit != 'true'
  35. run: yarn
  36. - name: Build
  37. run: npm run build
  38. env:
  39. NITRO_PRESET: azure-functions
  40. - name: 'Deploy to Azure Functions'
  41. uses: Azure/functions-action@v1
  42. with:
  43. app-name: <your-app-name>
  44. package: .output/deploy.zip
  45. publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}

Optimizing Azure Functions

Consider turning on immutable packages to support running your app from the zip file. This can speed up cold starts.