angular - GCP App Engine/Angular - 无法加载模块脚本 : The server responded with a non-JavaScript MIME type of "text/html"

标签 angular google-app-engine google-cloud-platform mime-types app.yaml

我正在尝试使用 App Engine 在 Google Cloud Platform 上托管 Angular 应用程序。问题是在我成功部署它之后,我可以访问它大约 2-3 分钟,点击刷新并且没有收到 HTTP 错误 404,但是在这 2-3 分钟之后我在 Chrome 中收到以下错误(同事在他们的机器上也收到同样的错误):

enter image description here

我尝试使用以下方法构建我的 Angular 应用程序:

ng build --prod
ng build --prod --base-href sep6-app

Angular 应用文件夹结构:

- dist/
  - sep6-app/
  - app.yaml

我的 app.yaml:

runtime: python27
api_version: 1
threadsafe: true

handlers:

- url: /.*
  static_files: sep6-app/index.html
  upload: sep6-app/index.html

- url: /.*
  static_dir: sep6-app

在 GCP 中,我的存储桶包含:

- app.yaml
- sep6-app/

有一件事,如果我像这样在 app.yaml 中设置 URL,然后重新部署:

- url: /
  static_files: sep6-app/index.html
  upload: sep6-app/index.html

- url: /
  static_dir: sep6-app

我可以毫无问题地访问我的应用程序,但是如果我刷新任何页面,我会收到 404 错误,据我所知,由于 Angular 处理路由的方式,这是预料之中的。但是我不明白为什么“- url:/.*”会在短时间内工作然后停止?

我正在使用(以防万一):

Angular CLI: 9.1.7
Angular: 9.1.9

关于为什么会发生这种情况以及如何解决这个问题,您有什么想法或想法吗?谢谢!

最佳答案

通过使用以下 app.yaml 设法让它工作:

runtime: python38
service: default

handlers:
- url: /(.*\.(gif|png|jpg|less|json|woff|woff2|ttf|eot|scss|css|js|ico|svg)(|\.map))$
  static_files: sep6-app/\1
  upload: sep6-app/(.*)(|\.map)
- url: /(.*)
  static_files: sep6-app/index.html
  upload: sep6-app/index.html

关于angular - GCP App Engine/Angular - 无法加载模块脚本 : The server responded with a non-JavaScript MIME type of "text/html",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61970036/

相关文章:

google-cloud-platform - 尝试在 google oauth 中为同意屏幕注册应用程序时出现问题

Kubernetes Cron 作业在创建下一个计划之前终止 Pod

javascript - Renderer2、ViewChild 和 ElementRef。为什么我们需要/在 Angular 中使用这些东西?

javascript - 如何使用 Amazon Cognito sdk 实现 *Remember me* 选项?

两个模块中的 Angular 路由优先级

python - 数据存储事务限制

python - 如何组织Python源代码文件?

python - 如何在 Mac OS X 10.6 上将 virtualenv 与 Google App Engine SDK 一起使用

mysql - 无法从谷歌云计算VM实例连接到独立的MySQL服务器

angular - 何时在angular中使用waitForAsync