Azure

将 Nitro 应用程序部署到 Cleavr。

Azure Static Web Apps

Preset: azure (switch to this preset)

零配置提供商

可以通过零配置与此提供程序集成。 了解更多

Azure 静态 Web 应用旨在在 GitHub 操作工作流 中持续部署。 默认情况下,Nitro 将检测此部署环境并启用“azure”预设。

Local preview

您可以在部署前调用开发环境进行预览。

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

Deploy from CI/CD via GitHub Actions

将 GitHub 存储库链接到 Azure 静态 Web 应用时,工作流文件将添加到存储库。

当系统要求您选择框架时,请选择自定义并提供以下信息:

InputValue
app_location'/'
api_location'.output/server'
output_location'.output/public'

如果您错过了这一步,您始终可以在工作流程中找到构建配置部分并更新构建配置:

yaml
# .github/workflows/azure-static-web-apps-<RANDOM_NAME>.yml

# ##### Repository/Build Configurations ######
app_location: /
api_location: .output/server
output_location: .output/public
# ##### End of Repository/Build Configurations ######

就是这样! 现在,Azure 静态 Web 应用程序将在推送时自动部署由 Nitro 驱动的应用程序。

如果您使用的是 runtimeConfig,则可能需要配置相应的 Azure 上的环境变量

Azure Functions

Preset: azure-functions

**注意:**如果您遇到任何问题,请确保您使用的是 Node.js 14+ 运行时。 您可以找到有关[如何在 Azure 文档中设置节点版本](https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-node?tabs=v2#setting -节点版本)。

Local preview

如果要在本地进行测试,请安装 Azure Functions Core Tools

您可以从无服务器目录调用开发环境。

bash
NITRO_PRESET=azure-functions yarn build
cd .output
func start

您现在可以在浏览器中访问“http://localhost:7071/”并浏览在 Azure Functions 上本地运行的站点。

从本地机器部署

要部署,只需运行以下命令:

bash
# 发布捆绑的 zip 文件
az functionapp deployment source config-zip -g <resource-group> -n <app-name> --src dist/deploy.zip
# 或者你可以从源发布
cd dist && func azure functionapp publish --javascript <app-name>

Deploy from CI/CD via GitHub Actions

首先,获取您的 Azure Functions 发布配置文件并按照 这些说明 将其作为秘密添加到您的 GitHub 存储库设置中 -受到推崇的。

然后创建以下文件作为工作流:

yaml
# .github/workflows/azure.yml
name: azure
on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main
jobs:
  deploy:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest]
        node: [14]
    steps:
      - uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node }}

      - name: Checkout
        uses: actions/checkout@master

      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"

      - uses: actions/cache@v2
        id: yarn-cache
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-azure

      - name: Install Dependencies
        if: steps.cache.outputs.cache-hit != 'true'
        run: yarn

      - name: Build
        run: npm run build
        env:
          NITRO_PRESET: azure-functions

      - name: Deploy to Azure Functions
        uses: Azure/functions-action@v1
        with:
          app-name: <your-app-name>
          package: .output/deploy.zip
          publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}

Optimizing Azure Functions

考虑打开不可变包 以支持从 zip 文件运行您的应用。 这可以加速冷启动。