Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ Locally preview the production build.

## Environment Variables

Create a `.env` file for local development or `.env.production` for production builds:
Create a `.env` file for local development or `.env.production` to override the production API endpoint:

```env
VITE_API_URL=http://localhost:7071/api
```

| Variable | Description | Default |
|----------|-------------|---------|
| `VITE_API_URL` | Backend API endpoint URL | `http://localhost:7071/api` |
| `VITE_API_URL` | Backend API endpoint URL | Local development: `http://localhost:7071/api`; production: `/api` |

## Local Development

Expand All @@ -93,7 +93,7 @@ VITE_API_URL=http://localhost:7071/api

4. **Ensure the backend is running**:

The frontend expects the Azure Functions backend to be running at the configured `VITE_API_URL`.
The frontend defaults to the local Azure Functions endpoint. In production, it defaults to `/api`, which the linked Static Web App backend routes to Azure Functions.

## Deployment

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import ProgressTracker from './ProgressTracker';
import './progress-tracker.css';

// Get API URL from environment variables
const API_URL = import.meta.env.VITE_API_URL || 'http://localhost:7071/api';
const API_URL = import.meta.env.VITE_API_URL
|| (import.meta.env.DEV ? 'http://localhost:7071/api' : '/api');

const ChatInterface = () => {
// Travel request state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Create a `local.settings.json` file in the root directory with the following con
"LOCAL_RECOMMENDATIONS_AGENT_ID": "<LOCAL_RECOMMENDATIONS_AGENT_ID>"
},
"Host": {
"LocalHttpPort": 7252,
"LocalHttpPort": 7071,
"CORS": "*",
"CORSCredentials": false
}
Expand Down Expand Up @@ -175,7 +175,7 @@ npm install
npm start
```

The application will be accessible at `http://localhost:3000`
The application will be accessible at `http://localhost:3000`. In development, the frontend calls `http://localhost:7071/api` by default. If you run the Functions host on a different port, create `Frontend/.env` with `VITE_API_URL=http://localhost:<port>/api`.

## Deploying to Azure

Expand Down Expand Up @@ -222,9 +222,19 @@ Follow the prompts to configure your environment settings.

### 3. Provision Resources and Deploy

Use the Azure Developer CLI to provision all necessary resources and deploy your application:
Use the Azure Developer CLI to provision all necessary resources and deploy your application. Set `SWA_CLI_DEPLOY_ENV=production` first so the frontend deploys to the Static Web App production environment, where the linked backend is available (see the note in [step 6](#6-deploy-react-web-app)).

#### Bash

```bash
export SWA_CLI_DEPLOY_ENV=production
azd up
```

#### PowerShell

```PowerShell
$env:SWA_CLI_DEPLOY_ENV = "production"
azd up
```

Expand Down Expand Up @@ -312,28 +322,23 @@ azd provision

### 6. Deploy React Web App

Update your `.env.production` file in `Frontend` directory so that it points to the correct API endpoint.
The deployed frontend uses the Static Web App's linked Function App backend at `/api` by default. To override this, set `VITE_API_URL` in `Frontend/.env.production` to the desired API endpoint.

> [!IMPORTANT]
> With azd 1.33 and Static Web Apps CLI 2.1, `azd deploy web` deployed the frontend to a preview environment that doesn't have the linked backend, so `/api` calls failed. Setting `SWA_CLI_DEPLOY_ENV=production` before deploying sent the frontend to the production environment, where the linked backend is available. This workaround was tested with `azd deploy --all`; it hasn't been verified as part of a complete `azd up` run. If the variable isn't set in your current shell, set it again before deploying.

#### Bash

```bash
STATIC_WEB_APP_URI=$(azd env get-value STATIC_WEB_APP_URI)
echo "REACT_APP_API_URL=$STATIC_WEB_APP_URI/api" > ./Frontend/.env.production

# Redeploy the build bundle.
azd package web
azd deploy web
export SWA_CLI_DEPLOY_ENV=production
azd deploy --all
```

#### PowerShell

```PowerShell
$staticWebAppUri = azd env get-value STATIC_WEB_APP_URI
"REACT_APP_API_URL=$staticWebAppUri/api" | Out-File -FilePath "./Frontend/.env.production" -Encoding utf8

# Redeploy the build bundle.
azd package web
azd deploy web
$env:SWA_CLI_DEPLOY_ENV = "production"
azd deploy --all
```

## Clean up
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ module functions 'br/public:avm/res/web/site:0.16.0' = {
tags: tags
serverFarmResourceId: appServicePlanId
managedIdentities: {
userAssignedResourceIds: [identityId]
systemAssigned: identityType == 'SystemAssigned'
userAssignedResourceIds: identityType == 'UserAssigned' ? [identityId] : []
}
siteConfig: {
netFrameworkVersion: 'v10.0'
Expand All @@ -61,15 +62,18 @@ module functions 'br/public:avm/res/web/site:0.16.0' = {
FUNCTIONS_WORKER_RUNTIME: 'dotnet-isolated'
AzureWebJobsStorage__accountName: storageAccount.name
AzureWebJobsStorage__credential : 'managedidentity'
APPLICATIONINSIGHTS_CONNECTION_STRING: applicationInsights.properties.ConnectionString
WEBSITE_USE_PLACEHOLDER_DOTNETISOLATED: '1'
})
},
!empty(applicationInsightsName) ? {
APPLICATIONINSIGHTS_CONNECTION_STRING: applicationInsights!.properties.ConnectionString
} : {})
}
]
}
}

output name string = functions.outputs.name
output uri string = 'https://${functions.outputs.defaultHostname}'
output identityPrincipalId string = identityType == 'SystemAssigned' ? functions.outputs.systemAssignedMIPrincipalId : ''
// A system-assigned identity is deployed whenever this output is needed.
output identityPrincipalId string = identityType == 'SystemAssigned' ? functions.outputs.systemAssignedMIPrincipalId! : ''
output id string = functions.outputs.resourceId
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ module api './app/api.bicep' = {
appSettings: {
// https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-configure-managed-identity
// These would be needed if running outside of cloud
AzureWebJobsStorage__blobServiceUri: 'https://${storage.outputs.name}.blob.core.windows.net'
AzureWebJobsStorage__queueServiceUri: 'https://${storage.outputs.name}.queue.core.windows.net'
AzureWebJobsStorage__tableServiceUri: 'https://${storage.outputs.name}.blob.core.windows.net'
AzureWebJobsStorage__blobServiceUri: storage.outputs.primaryEndpoints.blob
AzureWebJobsStorage__queueServiceUri: storage.outputs.primaryEndpoints.queue
AzureWebJobsStorage__tableServiceUri: storage.outputs.primaryEndpoints.table
AZURE_TENANT_ID: tenant().tenantId
AZURE_CLIENT_ID: apiUserAssignedIdentity.outputs.identityClientId
DURABLE_TASK_SCHEDULER_CONNECTION_STRING: 'Endpoint=${dts.outputs.dts_URL};Authentication=ManagedIdentity;ClientID=${apiUserAssignedIdentity.outputs.identityClientId}'
Expand All @@ -201,13 +201,8 @@ module api './app/api.bicep' = {
ITINERARY_PLANNER_AGENT_ID: itineraryPlannerAgentId
LOCAL_RECOMMENDATIONS_AGENT_ID: localRecommendationsAgentId
}
virtualNetworkSubnetId: skipVnet ? '' : serviceVirtualNetwork.outputs.appSubnetID
virtualNetworkSubnetId: skipVnet ? '' : serviceVirtualNetwork!.outputs.appSubnetID
}
dependsOn: [
storage
appServicePlan
apiUserAssignedIdentity
]
}

// Microsoft Foundry resource, project, and model deployment used by the agents
Expand Down Expand Up @@ -337,7 +332,7 @@ module storagePrivateEndpoint 'app/storage-private-endpoint.bicep' = if (!skipVn
location: location
tags: tags
virtualNetworkName: !empty(vNetName) ? vNetName : '${abbrs.networkVirtualNetworks}${resourceToken}'
subnetName: skipVnet ? '' : serviceVirtualNetwork.outputs.peSubnetName
subnetName: skipVnet ? '' : serviceVirtualNetwork!.outputs.peSubnetName
resourceName: storage.outputs.name
}
}
Expand Down Expand Up @@ -366,9 +361,6 @@ module appInsightsRoleAssignmentApi './core/monitor/appinsights-access.bicep' =
roleDefinitionID: monitoringRoleDefinitionId
principalID: apiUserAssignedIdentity.outputs.identityPrincipalId
}
dependsOn: [
apiUserAssignedIdentity
]
}

var durableTaskDataContributorRoleDefinitionId = '0ad04412-c4d5-4796-b79c-f76d14c8d402'
Expand All @@ -385,8 +377,6 @@ module dtsRoleAssignment 'app/dts-Access.bicep' = {
}
dependsOn: [
storage
apiUserAssignedIdentity
dts
]
}

Expand All @@ -399,9 +389,6 @@ module dtsDashboardRoleAssignment 'app/dts-Access.bicep' = {
principalType: 'User'
dtsName: dts.outputs.dts_NAME
}
dependsOn: [
dts
]
}

module dts './app/dts.bicep' = {
Expand Down
Loading