【问题标题】:AWS EC2 CodeDeploy doesn't load javascript from Angular dist folderAWS EC2 CodeDeploy 不会从 Angular dist 文件夹加载 javascript
【发布时间】:2019-10-08 04:17:09
【问题描述】:

我正在使用 Bitbucket Pipelines + AWS CodeDeploy + AWS EC2 实例来运行我的 Angular 应用程序。管道运行良好,代码是即时构建的,然后对于 EC2,它只上传 dist/ 文件夹。然后当我尝试访问我的页面时,没有加载 css 文件和 js 文件。

我尝试使用 stackoverflow 的其他解决方案,但没有任何效果。 EC2 在 Ubuntu 18.04 上的 apache2 上运行。

我尝试授予执行 js 文件的权限,但它也不起作用。

所有文件都在同一个目录中。

/deployment-id/deploment-archive/
-index.html
-runtime.js
-main.js
-polyfills.js
-runtime.js
-styles.css

index.html

<script type="text/javascript" src="runtime26209474bfa8dc87a77c.js"></script>
<script type="text/javascript" src="es2015-polyfillsbda95d5896422d031328.js" nomodule></script>
<script type="text/javascript" src="polyfills8bbb231b43165d65d357.js"></script>
<script type="text/javascript" src="maindcabcbb8258040c4d925.js"></script>

目前它只呈现空白页面,并且我在控制台中收到警告“使用源 www.myawslink.com/main.js 加载失败”

当我尝试直接访问文件时,apache 说“找不到 404 个文件”,但是当我通过 putty 连接到 ec2 时,我在部署目录中看到带有 index.html 的文件。我希望页面能够正确呈现,并且 js 文件能够正常工作。

【问题讨论】:

    标签: javascript angular amazon-web-services amazon-ec2 aws-code-deploy


    【解决方案1】:

    好的,问题出在 apache2 上。

    因为文件是从 /var/www/html/ 提供的,而在我的 appspec.yml 中,我在这里只包含了 index.html

    所以我改变了这个

      - source: /index.html
        destination: /var/www/html/
    

    到这里

      - source: /dist
        destination: /var/www/html/
    

    现在一切正常。

    我的 bitbucket-pipeline.yml 看起来像这样

    pipelines:
      default:
        - step:
            name: build angular
            image: node:10
            caches:
              - node
            script:
              - npm install
              - npm install -g @angular/cli
              - ng build --prod
            artifacts:
              - dist/**
        - step:
            name: deploy
            image: python:3.5.1
            script:
              - apt-get update # required to install zip
              - apt-get install -y zip # required for packaging up the application
              - pip install boto3==1.3.0 # required for codedeploy_deploy.py
              - zip -r /tmp/artifact.zip dist/* scripts/* appspec.yml package.json # package up the application for deployment
              - python codedeploy_deploy.py # run the deployment script
    

    【讨论】:

      猜你喜欢
      • 2016-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-22
      • 2018-06-04
      • 1970-01-01
      • 2018-06-21
      • 1970-01-01
      相关资源
      最近更新 更多