【发布时间】:2020-08-17 19:53:11
【问题描述】:
老实说,我觉得这很烦人,以至于这种情况一直在变化。 我在这里用更简单的 Angular 版本解决了这个问题:
Deploying Angular Universal to Azure
但现在这已经过时了。 不再生成 server.js,而是您必须修改您的 web.config 以指向 main.js,这听起来像是一种改进。 我将我的 yaml 更新为:
pool:
name: Azure Pipelines
steps:
- task: gittools.gitversion.gitversion-task.GitVersion@5
displayName: GitVersion
- task: NodeTool@0
displayName: 'Use Node 12.x'
inputs:
versionSpec: 12.x
- task: Npm@1
displayName: 'npm install angular cli'
inputs:
command: custom
verbose: false
customCommand: 'install @angular/cli -g'
- task: Npm@1
displayName: 'npm install'
inputs:
verbose: false
- task: Npm@1
displayName: 'npm build'
inputs:
command: custom
verbose: false
customCommand: 'run build:ssr'
- task: CopyFiles@2
displayName: 'Copy dist files to staging'
inputs:
SourceFolder: '$(Build.SourcesDirectory)/dist'
TargetFolder: '$(Build.ArtifactStagingDirectory)/app/dist'
- task: AzureRmWebAppDeployment@4
displayName: 'Azure App Service Deploy: app-name'
inputs:
azureSubscription: 'Pay-As-You-Go (f61dc7cf-0ca2-4982-bbe7-9b6527c2962b)'
WebAppName: r3plica
packageForLinux: '$(Build.ArtifactStagingDirectory)/app'
WebConfigParameters: '-Handler iisnode -NodeStartFile dist/app-name/server/main.js -appType node'
应该就是这样,但当然,事情没那么简单。 现在,如果我运行 node dist/app-name/server/main.js,我会收到错误消息。它返回这个:
ReferenceError: Blob 未在 createBase64WorkerFactory 中定义 (D:\home\site\wwwroot\dist\app-name\server\main.js:1:1418371)
所以我环顾四周,有人建议我安装 npm install --save-dev blob-polyfill,我照做了,然后编辑 server.ts 文件:
import { Blob } from 'blob-polyfill';
global['Blob'] = Blob;
但这似乎没有做任何事情。错误仍然存在。 有谁知道我必须做什么?
更新
我决定今天再试一次。
我运行 npm build:ssr 并将 server & browser 文件夹复制到本地网络服务器并运行 node server/main.js 并抱怨它在 dist/my- 找不到 index.html 文件project/browser/index.html 这对我有帮助。
所以我将整个 dist 文件夹复制到 wwwroot 并运行 node dist/my-project/server/main.js,它成功了。
所以我更新了我的管道来做同样的事情。我验证它实际上复制了整个 dist 文件夹,然后我将 web.config 复制到根目录。 我的 web.config 文件如下所示:
<configuration>
<system.web>
<customErrors mode="Off" />
</system.web>
<system.webServer>
<staticContent>
<remove fileExtension=".woff2" />
<mimeMap fileExtension=".woff2" mimeType="font/woff2" />
</staticContent>
<handlers>
<!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
<add name="iisnode" path="dist/my-project/server/main.js" verb="*" modules="iisnode"/>
</handlers>
<httpErrors errorMode="Detailed"></httpErrors>
</system.webServer>
</configuration>
但是当我尝试加载我的网站时,它只会给我一个错误:
HTTP 错误 403.14 - 禁止
请求的 URL 没有配置默认文档,并且服务器上没有启用目录浏览。
这真的很烦人。
我查看了https://example.scm.azurewebsites.net,然后转到调试控制台并输入node dist/my-project/server/main.js,它返回:
Node Express 服务器监听 http://localhost:4000
所以据我所知,它应该可以正常工作。 有谁知道为什么不是?
【问题讨论】:
-
嗨,r3plica。几天以来我遇到了完全相同的问题......你能取得任何进展或给我任何关于如何部署我们的应用程序的提示吗? (烦人是一个非常礼貌的词,顺便说一句)......
标签: angular azure angular-universal