简体   繁体   English

Angular 使用 Azure 部署 Devops 未加载 — 显示“嘿节点开发人员!” 页

[英]Angular Deployment using Azure Devops doesn't load — shows “hey node developers!” page

I'm trying to deploy an angular app to Azure, the deployment seems to work, the artifacts look correct, however when I go to the website I am shown the default Azure "hey node developers" page. I'm trying to deploy an angular app to Azure, the deployment seems to work, the artifacts look correct, however when I go to the website I am shown the default Azure "hey node developers" page. See ( http://testss-123.azurewebsites.net/ )请参阅( http://testss-123.azurewebsites.net/

My build pipeline is as follows:我的构建管道如下:

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js'

- script: |
    npm install -g @angular/cli
    npm install
    ng build --prod
  displayName: 'npm install and build'
  workingDirectory: '$(Build.SourcesDirectory)'

- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: '$(Build.SourcesDirectory)/dist'
    includeRootFolder: true
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    replaceExistingArchive: true

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

and my deployment pipeline is the default "Deploy a Node.js app to Azure App Service" see here我的部署管道是默认的“将 Node.js 应用程序部署到 Azure 应用程序服务”,请参见此处

I have tried this both with an actual app, and also with the default app built buy "ng new"我已经用一个实际的应用程序试过这个,也用默认的应用程序构建购买“ng new”

I was unable to solve this problem, however as a workaround I deployed the app in a docker container, with the following dockerfile我无法解决此问题,但是作为一种解决方法,我将应用程序部署在 docker 容器中,并使用以下 dockerfile

FROM node:latest AS node

WORKDIR /app

COPY . .

RUN npm install && \
    npm run build-prod

FROM nginx:alpine
COPY --from=node /app/dist/superselection/nginx.conf /etc/nginx/conf.d/default.conf

COPY --from=node /app/dist/* /usr/share/nginx/html

the following nginx conf file in my src folder:我的 src 文件夹中的以下 nginx conf 文件:

server {
  listen 80;
  location / {
    root /usr/share/nginx/html;
    index index.html index.htm;
    try_files $uri $uri/ /index.html;
  }
}

and finally the following build pipeline:最后是以下构建管道:

pool:
  name: Azure Pipelines
steps:
- task: Docker@0
  displayName: 'Build an image'
  inputs:
    azureSubscription: XXXXXXXX
    azureContainerRegistry: XXXXXXXX
    defaultContext: false
    context: '$(System.DefaultWorkingDirectory)'

- task: Docker@0
  displayName: 'Push an image'
  inputs:
    azureSubscription: XXXXXXXX
    azureContainerRegistry: XXXXXXXX
    action: 'Push an image'

Your Azure WebApp is running on an IIS instance by default.默认情况下,您的 Azure WebApp 正在 IIS 实例上运行。 If you want to handle the Html5 Mode(without the hashbang) then you have to create a Web.Config file and define a rewrite.如果你想处理 Html5 模式(没有 hashbang),那么你必须创建一个 Web.Config 文件并定义一个重写。

<configuration>
   <system.webServer>
      <defaultDocument enabled="true">
         <files>
            <add value="index.html" />
         </files>
      </defaultDocument>
   </system.webServer>
</configuration>

If you login http://testss-123.scm.azurewebsites.net/ .如果您登录http://testss-123.scm.azurewebsites.net/ You will probably find your code was deployed to folder site/wwwroot/dist/yourapp , install of site/wwwroot .您可能会发现您的代码已部署到文件夹site/wwwroot/dist/yourapp ,安装site/wwwroot It might cause this issue.它可能会导致此问题。

You can modify your archiveFiles task as below.您可以如下修改您的 archiveFiles 任务。 Point the rootFolderOrFile to the app-name folder under dist folder.rootFolderOrFile指向dist文件夹下的app-name文件夹。 And set includeRootFolder to false.并将includeRootFolder设置为 false。

so that the output zip file only contain your ready-to-deploy code.以便 output zip 文件仅包含您可以部署的代码。

- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: '$(Build.SourcesDirectory)/dist/<yourapp>'
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    replaceExistingArchive: true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM