# Azure Static Web Apps

Quick reference for Azure Static Web Apps deployment.

## Features

- Automatic GitHub/GitLab CI/CD
- Free SSL certificates
- Global CDN distribution
- Serverless API with Azure Functions
- Authentication providers built-in

## GitHub Actions Workflow

```yaml
# .github/workflows/azure-static-web-apps.yml
name: Azure Static Web Apps CI/CD

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  build_and_deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Build And Deploy
        uses: Azure/static-web-apps-deploy@v1
        with:
          azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }}
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          action: "upload"
          app_location: "/"
          api_location: "api"
          output_location: "dist"
```

## Configuration

```json
// staticwebapp.config.json
{
  "routes": [
    {
      "route": "/api/*",
      "allowedRoles": ["authenticated"]
    },
    {
      "route": "/*",
      "serve": "/index.html",
      "statusCode": 200
    }
  ],
  "navigationFallback": {
    "rewrite": "/index.html",
    "exclude": ["/images/*.{png,jpg}", "/api/*"]
  },
  "responseOverrides": {
    "404": {
      "redirect": "/",
      "statusCode": 302
    }
  }
}
```

## Authentication

```json
// staticwebapp.config.json
{
  "auth": {
    "identityProviders": {
      "azureActiveDirectory": {
        "registration": {
          "openIdIssuer": "https://login.microsoftonline.com/{tenant-id}/v2.0",
          "clientIdSettingName": "AAD_CLIENT_ID",
          "clientSecretSettingName": "AAD_CLIENT_SECRET"
        }
      }
    }
  }
}
```

## Environment Variables

```bash
# Set in Azure Portal or CLI
az staticwebapp appsettings set \
  --name my-app \
  --setting-names "API_KEY=secret123"
```

## CLI Commands

```bash
# Install CLI
npm install -g @azure/static-web-apps-cli

# Start local dev
swa start ./dist --api-location ./api

# Deploy
swa deploy ./dist --env production
```

## Links

- [Azure SWA Docs](https://learn.microsoft.com/azure/static-web-apps/)
- [CLI Reference](https://azure.github.io/static-web-apps-cli/)
