Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Prepare Azure environments for new workloads—subscriptions, networking, identity, and landing zones
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/services/app-service/templates/web-app.md
1# Full-Stack Web App Template — REFERENCE ONLY23Template for server-side rendered web applications on Azure App Service. Use for MVC, Razor Pages, Next.js SSR, Django, or React+API patterns.45## Templates by Pattern67| Pattern | AZD Template | Framework |8|---------|-------------|-----------|9| React + C# API | `azd init -t todo-csharp` | React SPA + ASP.NET Core API |10| React + Node.js API | `azd init -t todo-nodejs-mongo` | React SPA + Express API |11| React + Python API | `azd init -t todo-python-mongo` | React SPA + FastAPI |12| React + Java API | `azd init -t todo-java-mongo` | React SPA + Spring Boot |1314**Browse all:** [Awesome AZD](https://azure.github.io/awesome-azd/?tags=appservice)1516> 💡 **Tip:** For static frontends with API backends, consider Azure Static Web Apps instead. Use App Service when you need full server-side rendering.1718## Architecture Patterns1920### Pattern A: Single App Service (API + static files)2122```23App Service (Linux)24├── /api/* → Backend routes25└── /* → Static files (React/Vue build output)26```2728Best for: Simple apps, MVPs, Razor Pages, Django with templates.2930### Pattern B: Separate frontend + backend3132```33App Service (frontend) ← React/Next.js SSR34│35└──► App Service (backend) ← REST API36```3738Best for: Independent scaling, team separation, microservices.3940## Project Structure (Single App)4142```43project-root/44├── azure.yaml45├── infra/46│ ├── main.bicep47│ └── app/48│ └── web.bicep49└── src/50├── api/ # Backend51│ ├── Program.cs # or app.py / index.js52│ └── ...53└── web/ # Frontend (built output served as static)54├── package.json55└── src/56```5758## azure.yaml (multi-service)5960```yaml61name: my-web-app62services:63web:64project: ./src/web65host: appservice66language: js67dist: build68api:69project: ./src/api70host: appservice71language: csharp72```7374## Server-Side Rendering Examples7576### ASP.NET Core MVC / Razor Pages7778```csharp79var builder = WebApplication.CreateBuilder(args);80builder.Services.AddControllersWithViews();81var app = builder.Build();82app.UseStaticFiles();83app.MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=Index}/{id?}");84app.MapGet("/health", () => Results.Ok(new { status = "healthy" }));85app.Run();86```8788### Next.js (SSR on App Service)8990```javascript91// next.config.js92module.exports = {93output: 'standalone', // Required for App Service deployment94};95```9697Startup command in App Service:98```bash99node server.js100```101102### Django103104```python105# settings.py106ALLOWED_HOSTS = ['.azurewebsites.net', 'localhost']107STATIC_ROOT = BASE_DIR / 'staticfiles'108CSRF_TRUSTED_ORIGINS = ['https://*.azurewebsites.net']109```110111### Express + React (served from build)112113```javascript114const express = require('express');115const path = require('path');116const app = express();117118app.use(express.json());119app.use('/api', apiRouter);120app.use(express.static(path.join(__dirname, '../web/build')));121app.get('/health', (req, res) => res.json({ status: 'healthy' }));122app.get('*', (req, res) => {123res.sendFile(path.join(__dirname, '../web/build/index.html'));124});125126app.listen(process.env.PORT || 3000);127```128129## App Service Configuration130131```bicep132resource webApp 'Microsoft.Web/sites@2023-12-01' = {133properties: {134siteConfig: {135linuxFxVersion: 'NODE|20-lts' // or DOTNETCORE|8.0, PYTHON|3.12136healthCheckPath: '/health'137appCommandLine: '' // Custom startup command if needed138appSettings: [139{ name: 'SCM_DO_BUILD_DURING_DEPLOYMENT', value: 'true' }140{ name: 'WEBSITE_NODE_DEFAULT_VERSION', value: '~20' }141]142}143}144tags: {145'azd-service-name': 'web'146}147}148```149150## Startup Commands by Runtime151152| Runtime | Startup Command | Notes |153|---------|----------------|-------|154| ASP.NET Core | (auto-detected) | No command needed |155| Node.js | `node server.js` or `npm start` | Set via `appCommandLine` |156| Python (Django) | `gunicorn myapp.wsgi` | Use gunicorn for production |157| Python (FastAPI) | `uvicorn main:app --host 0.0.0.0` | Use uvicorn for ASGI |158| Next.js SSR | `node server.js` | Use `output: 'standalone'` |159160## Deployment161162```bash163ENV_NAME="$(basename "$PWD" | tr '[:upper:]' '[:lower:]' | tr ' _' '-')-dev"164azd init -t <template> -e "$ENV_NAME" --no-prompt165azd env set AZURE_LOCATION eastus2166azd up --no-prompt167```168169**PowerShell:**170```powershell171$ENV_NAME = "$(Split-Path -Leaf (Get-Location) | ForEach-Object { $_.ToLower() -replace '[ _]','-' })-dev"172azd init -t <template> -e $ENV_NAME --no-prompt173azd env set AZURE_LOCATION eastus2174azd up --no-prompt175```176177## References178179- [Deploy to App Service](https://learn.microsoft.com/en-us/azure/app-service/quickstart-dotnetcore)180- [Node.js on App Service](https://learn.microsoft.com/en-us/azure/app-service/quickstart-nodejs)181- [Python on App Service](https://learn.microsoft.com/en-us/azure/app-service/quickstart-python)182