I’m trying to deploy my Angular Universal app to Azure Web App Service.
Locally npm run build:ssr && npm run serve:ssr
works good.
Without ssr rendering npm run start
works good too.
To deploy simple app without ssr works on my hosting good too. I have a problem only with deploy of ssr.
My web config for ssr
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="main.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="DynamicContent">
<match url="/*" />
<action type="Rewrite" url="main.js"/>
</rule>
<rule name="StaticContent" stopProcessing="true">
<match url="([S]+[.](jpg|jpeg|gif|css|png|js|ts|cscc|less|ico|html|map|svg))" />
<action type="None" />
</rule>
</rules>
</rewrite>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" />
<remove fileExtension=".svg" />
<remove fileExtension=".eot" />
<remove fileExtension=".ttf" />
<remove fileExtension=".woff" />
<remove fileExtension=".woff2" />
<remove fileExtension=".otf" />
<mimeMap fileExtension=".ttf" mimeType="application/octet-stream" />
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
<mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
<mimeMap fileExtension=".woff" mimeType="application/x-woff" />
<mimeMap fileExtension=".woff2" mimeType="application/x-woff" />
<mimeMap fileExtension=".otf" mimeType="application/otf" />
</staticContent>
</system.webServer>
</configuration>
My azure pipline for ssr
first case
# Node.js with Angular
# Build a Node.js project that uses Angular.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
- masters
pool:
vmImage: ubuntu-latest
steps:
- task: NodeTool@0
inputs:
versionSpec: '18.x'
displayName: 'Install Node.js'
- script: |
npm install -g @angular/cli
npm install --force
npm outdated
npm run build:ssr --prod
displayName: 'npm install and build'
- task: CopyFiles@2
inputs:
targetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: 'dist'
ArtifactName: 'dist'
Second case
# Node.js with Angular
# Build a Node.js project that uses Angular.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
- masters
pool:
vmImage: ubuntu-latest
steps:
- task: NodeTool@0
inputs:
versionSpec: '18.x'
displayName: 'Install Node.js'
- script: |
npm install -g @angular/cli
npm install --force
npm outdated
npm run build:ssr --prod
displayName: 'npm install and build'
- task: CopyFiles@1
displayName: 'Copy browser directory from dist directory to the root'
inputs:
SourceFolder: '$(Build.SourcesDirectory)/dist'
TargetFolder: '$(Build.ArtifactStagingDirectory)/app-name'
- task: CopyFiles@2
displayName: 'Copy main.js to the root'
inputs:
SourceFolder: '$(Build.ArtifactStagingDirectory)/app-name/dist'
Contents: main.js
TargetFolder: '$(Build.ArtifactStagingDirectory)/app-name'
- task: DeleteFiles@1
displayName: 'Delete the dist/main.js'
inputs:
SourceFolder: '$(Build.ArtifactStagingDirectory)/app-name/dist'
Contents: 'main.js'
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: 'dist'
ArtifactName: 'dist'
And in result I have this
My way to root artifacts on Azure Web App configuration works well. My app can’t run only Angular SSR. Where is the mistake? In the pipeline or in the config file?
2
Answers
I used below YAML code to deploy Angular Universal app in my Azure DevOps pipeline:-
Output:-
Deployment was successful, Refer below:-
To resolve your error, Check the application logs in your Azure Web app Log stream like below:-
Reference:- MS Document1
Validate your Web.config file and also while running your Pipeline Enable Debugging to get more insights on your Pipeline run.
You can also check the Logs by visiting the Kudu tool and see if the Deployment was successful. by visitng Deployment Logs and checking your code Files.
To create an Azure pipeline for an Angular Universal app, you can follow the below steps:
npm install
command to install all the dependencies for your Angular Universal app.npm run build:ssr
to generate the server-side rendered output of the app.These are the basic steps to create an Azure pipeline for an Angular Universal app. You can customize the pipeline based on your specific requirements.