Skip to content

Commit

Permalink
with web
Browse files Browse the repository at this point in the history
  • Loading branch information
pdebruin committed Apr 8, 2024
1 parent d243380 commit 9ca032f
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 170 deletions.
240 changes: 120 additions & 120 deletions 5azd/infra/app/apim-api.bicep
Original file line number Diff line number Diff line change
@@ -1,120 +1,120 @@
param name string

@description('Resource name to uniquely identify this API within the API Management service instance')
@minLength(1)
param apiName string

@description('The Display Name of the API')
@minLength(1)
@maxLength(300)
param apiDisplayName string

@description('Description of the API. May include HTML formatting tags.')
@minLength(1)
param apiDescription string

@description('Relative URL uniquely identifying this API and all of its resource paths within the API Management service instance. It is appended to the API endpoint base URL specified during the service instance creation to form a public URL for this API.')
@minLength(1)
param apiPath string

@description('Absolute URL of the web frontend')
param webFrontendUrl string

@description('Absolute URL of the backend service implementing this API.')
param apiBackendUrl string

@description('Resource name for backend Web App or Function App')
param apiAppName string = ''

var apiPolicyContent = replace(loadTextContent('./apim-api-policy.xml'), '{origin}', webFrontendUrl)

resource restApi 'Microsoft.ApiManagement/service/apis@2021-12-01-preview' = {
name: apiName
parent: apimService
properties: {
description: apiDescription
displayName: apiDisplayName
path: apiPath
protocols: [ 'https' ]
subscriptionRequired: false
type: 'http'
format: 'openapi'
serviceUrl: apiBackendUrl
value: loadTextContent('../../src/api/openapi.yaml')
}
}

resource apiPolicy 'Microsoft.ApiManagement/service/apis/policies@2021-12-01-preview' = {
name: 'policy'
parent: restApi
properties: {
format: 'rawxml'
value: apiPolicyContent
}
}

resource apiDiagnostics 'Microsoft.ApiManagement/service/apis/diagnostics@2021-12-01-preview' = {
name: 'applicationinsights'
parent: restApi
properties: {
alwaysLog: 'allErrors'
backend: {
request: {
body: {
bytes: 1024
}
}
response: {
body: {
bytes: 1024
}
}
}
frontend: {
request: {
body: {
bytes: 1024
}
}
response: {
body: {
bytes: 1024
}
}
}
httpCorrelationProtocol: 'W3C'
logClientIp: true
loggerId: apimLogger.id
metrics: true
sampling: {
percentage: 100
samplingType: 'fixed'
}
verbosity: 'verbose'
}
}

resource apimService 'Microsoft.ApiManagement/service@2021-08-01' existing = {
name: name
}

// Necessary due to https://github.com/Azure/bicep/issues/9594
// placeholderName is never deployed, it is merely used to make the child name validation pass
var appNameForBicep = !empty(apiAppName) ? apiAppName : 'placeholderName'

resource apiAppProperties 'Microsoft.Web/sites/config@2022-03-01' = if (!empty(apiAppName)) {
name: '${appNameForBicep}/web'
kind: 'string'
properties: {
apiManagementConfig: {
id: '${apimService.id}/apis/${apiName}'
}
}
}

resource apimLogger 'Microsoft.ApiManagement/service/loggers@2021-12-01-preview' existing = {
name: 'app-insights-logger'
parent: apimService
}

output SERVICE_API_URI string = '${apimService.properties.gatewayUrl}/${apiPath}'
// param name string

// @description('Resource name to uniquely identify this API within the API Management service instance')
// @minLength(1)
// param apiName string

// @description('The Display Name of the API')
// @minLength(1)
// @maxLength(300)
// param apiDisplayName string

// @description('Description of the API. May include HTML formatting tags.')
// @minLength(1)
// param apiDescription string

// @description('Relative URL uniquely identifying this API and all of its resource paths within the API Management service instance. It is appended to the API endpoint base URL specified during the service instance creation to form a public URL for this API.')
// @minLength(1)
// param apiPath string

// @description('Absolute URL of the web frontend')
// param webFrontendUrl string

// @description('Absolute URL of the backend service implementing this API.')
// param apiBackendUrl string

// @description('Resource name for backend Web App or Function App')
// param apiAppName string = ''

// var apiPolicyContent = replace(loadTextContent('./apim-api-policy.xml'), '{origin}', webFrontendUrl)

// resource restApi 'Microsoft.ApiManagement/service/apis@2021-12-01-preview' = {
// name: apiName
// parent: apimService
// properties: {
// description: apiDescription
// displayName: apiDisplayName
// path: apiPath
// protocols: [ 'https' ]
// subscriptionRequired: false
// type: 'http'
// format: 'openapi'
// serviceUrl: apiBackendUrl
// value: loadTextContent('../../src/api/openapi.yaml')
// }
// }

// resource apiPolicy 'Microsoft.ApiManagement/service/apis/policies@2021-12-01-preview' = {
// name: 'policy'
// parent: restApi
// properties: {
// format: 'rawxml'
// value: apiPolicyContent
// }
// }

// resource apiDiagnostics 'Microsoft.ApiManagement/service/apis/diagnostics@2021-12-01-preview' = {
// name: 'applicationinsights'
// parent: restApi
// properties: {
// alwaysLog: 'allErrors'
// backend: {
// request: {
// body: {
// bytes: 1024
// }
// }
// response: {
// body: {
// bytes: 1024
// }
// }
// }
// frontend: {
// request: {
// body: {
// bytes: 1024
// }
// }
// response: {
// body: {
// bytes: 1024
// }
// }
// }
// httpCorrelationProtocol: 'W3C'
// logClientIp: true
// loggerId: apimLogger.id
// metrics: true
// sampling: {
// percentage: 100
// samplingType: 'fixed'
// }
// verbosity: 'verbose'
// }
// }

// resource apimService 'Microsoft.ApiManagement/service@2021-08-01' existing = {
// name: name
// }

// // Necessary due to https://github.com/Azure/bicep/issues/9594
// // placeholderName is never deployed, it is merely used to make the child name validation pass
// var appNameForBicep = !empty(apiAppName) ? apiAppName : 'placeholderName'

// resource apiAppProperties 'Microsoft.Web/sites/config@2022-03-01' = if (!empty(apiAppName)) {
// name: '${appNameForBicep}/web'
// kind: 'string'
// properties: {
// apiManagementConfig: {
// id: '${apimService.id}/apis/${apiName}'
// }
// }
// }

// resource apimLogger 'Microsoft.ApiManagement/service/loggers@2021-12-01-preview' existing = {
// name: 'app-insights-logger'
// parent: apimService
// }

// output SERVICE_API_URI string = '${apimService.properties.gatewayUrl}/${apiPath}'
72 changes: 36 additions & 36 deletions 5azd/infra/app/db.bicep
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
param accountName string
param location string = resourceGroup().location
param tags object = {}
// param accountName string
// param location string = resourceGroup().location
// param tags object = {}

param collections array = [
{
name: 'TodoList'
id: 'TodoList'
shardKey: 'Hash'
indexKey: '_id'
}
{
name: 'TodoItem'
id: 'TodoItem'
shardKey: 'Hash'
indexKey: '_id'
}
]
param databaseName string = ''
param keyVaultName string
// param collections array = [
// {
// name: 'TodoList'
// id: 'TodoList'
// shardKey: 'Hash'
// indexKey: '_id'
// }
// {
// name: 'TodoItem'
// id: 'TodoItem'
// shardKey: 'Hash'
// indexKey: '_id'
// }
// ]
// param databaseName string = ''
// param keyVaultName string

// Because databaseName is optional in main.bicep, we make sure the database name is set here.
var defaultDatabaseName = 'Todo'
var actualDatabaseName = !empty(databaseName) ? databaseName : defaultDatabaseName
// // Because databaseName is optional in main.bicep, we make sure the database name is set here.
// var defaultDatabaseName = 'Todo'
// var actualDatabaseName = !empty(databaseName) ? databaseName : defaultDatabaseName

module cosmos '../core/database/cosmos/mongo/cosmos-mongo-db.bicep' = {
name: 'cosmos-mongo'
params: {
accountName: accountName
databaseName: actualDatabaseName
location: location
collections: collections
keyVaultName: keyVaultName
tags: tags
}
}
// module cosmos '../core/database/cosmos/mongo/cosmos-mongo-db.bicep' = {
// name: 'cosmos-mongo'
// params: {
// accountName: accountName
// databaseName: actualDatabaseName
// location: location
// collections: collections
// keyVaultName: keyVaultName
// tags: tags
// }
// }

output connectionStringKey string = cosmos.outputs.connectionStringKey
output databaseName string = cosmos.outputs.databaseName
output endpoint string = cosmos.outputs.endpoint
// output connectionStringKey string = cosmos.outputs.connectionStringKey
// output databaseName string = cosmos.outputs.databaseName
// output endpoint string = cosmos.outputs.endpoint
28 changes: 14 additions & 14 deletions 5azd/infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ param keyVaultName string = ''
param logAnalyticsName string = ''
param resourceGroupName string = ''
param storageAccountName string = ''
// param webServiceName string = ''
param webServiceName string = ''
// param apimServiceName string = ''

@description('Flag to use Azure API Management to mediate the calls between the Web frontend and the backend API')
Expand All @@ -46,16 +46,16 @@ resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = {
tags: tags
}

// // The application frontend
// module web './app/web.bicep' = {
// name: 'web'
// scope: rg
// params: {
// name: !empty(webServiceName) ? webServiceName : '${abbrs.webStaticSites}web-${resourceToken}'
// location: location
// tags: tags
// }
// }
// The application frontend
module web './app/web.bicep' = {
name: 'web'
scope: rg
params: {
name: !empty(webServiceName) ? webServiceName : '${abbrs.webStaticSites}web-${resourceToken}'
location: location
tags: tags
}
}

// The application backend
module api './app/api.bicep' = {
Expand Down Expand Up @@ -192,8 +192,8 @@ output AZURE_KEY_VAULT_ENDPOINT string = keyVault.outputs.endpoint
output AZURE_KEY_VAULT_NAME string = keyVault.outputs.name
output AZURE_LOCATION string = location
output AZURE_TENANT_ID string = tenant().tenantId
// output REACT_APP_API_BASE_URL string = useAPIM ? apimApi.outputs.SERVICE_API_URI : api.outputs.SERVICE_API_URI
// output REACT_APP_APPLICATIONINSIGHTS_CONNECTION_STRING string = monitoring.outputs.applicationInsightsConnectionString
// output REACT_APP_WEB_BASE_URL string = web.outputs.SERVICE_WEB_URI
output REACT_APP_API_BASE_URL string = useAPIM ? apimApi.outputs.SERVICE_API_URI : api.outputs.SERVICE_API_URI
output REACT_APP_APPLICATIONINSIGHTS_CONNECTION_STRING string = monitoring.outputs.applicationInsightsConnectionString
output REACT_APP_WEB_BASE_URL string = web.outputs.SERVICE_WEB_URI
output USE_APIM bool = useAPIM
// output SERVICE_API_ENDPOINTS array = useAPIM ? [ apimApi.outputs.SERVICE_API_URI, api.outputs.SERVICE_API_URI ]: []

0 comments on commit 9ca032f

Please sign in to comment.