我正在尝试将我的Angular Universal应用部署到Azure Web App Service。npm run build:ssr && npm run serve:ssr
在本地运行良好。
没有ssr渲染npm run start
也能很好地工作。
部署简单的应用程序没有ssr工程我的主机太好.我只对ssr的部署有问题。
我的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>
我的 Azure 管道为ssr
第一例
# 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'
第二个案例
# 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'
结果我得到了这个
我在Azure Web App配置上根工件的方法运行良好。我的应用程序不能只运行Angular SSR。错在哪里?在管道中还是在配置文件中?
2条答案
按热度按时间t98cgbkg1#
我使用以下YAML代码在Azure DevOps管道中部署Angular Universal应用程序:-
输出:-
展开成功,请参阅以下内容:-
要解决错误,请检查Azure Web应用日志流中的应用日志,如下所示:-
参考:-MS Document1
验证您的Web.config文件,并在运行您的Pipeline时启用调试,以获得有关Pipeline运行的更多信息。
您也可以通过访问Kudu工具查看日志,查看部署是否成功。通过访问部署日志并检查代码文件。
参考:-Ms Document2
0wi1tuuw2#
要为Angular Universal应用创建Azure管道,您可以按照以下步骤操作:
1.设置构建管道:
1.安装依赖项:
npm install
命令来安装Angular Universal应用的所有依赖项。1.构建app:
npm run build:ssr
以生成应用的服务器端呈现输出。1.发布工件:
1.设置发布管道:
1.测试app:
1.部署应用程序:
以下是为Angular Universal应用创建Azure管道的基本步骤。您可以根据您的特定要求自定义管道。