子目录中应用程序的角度部署问题

问题描述 投票:0回答:1

我收到“无法加载模块脚本:需要 JavaScript 模块脚本,但服务器响应的 MIME 类型为“text/html”。根据 HTML 规范对模块脚本强制执行严格的 MIME 类型检查。”部署角度应用程序后出错。

在安装 Nx 之前应用程序运行良好。我现在正试图摆脱 Nx。

据我调查,所有人都说问题是 base-href 丢失了,但事实并非如此。我把它放在 package.json 中,它完美地导出到 index.html 文件中。

这是 package.json 中的部分:

  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "prebuild": "npm --no-git-tag-version version patch",
    "build": "ng build",
    "prebuild-local": "npm --no-git-tag-version version patch",
    "build-local": "ng build --configuration=local --base-href=/app_name/angular/",
    "build-prod": "ng build --configuration=prod --base-href=/AppName/angular/",
    "build-test": "ng build --configuration=testing --base-href=/AppName/angular/",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },

这就是我在 index.html 中得到的

<base href="/app_name/angular/">

我使用此命令创建分发文件:

npm run build-local
然后将文件复制到
http://localhost:8080/app_name/angular/

中的 Apache Tomcat

我在 Tomcat 中添加了“重写”规则,如 CodeDumpster

所建议的那样

重写规则就像

RewriteRule ^/app_name/angular/(.*) /app_name/angular/index.html

我还能检查什么?

angular url-rewriting tomcat9
1个回答
0
投票

找到解决方案。

问题不在于 Angular 或 Nx 安装。这是重写规则的问题。

我遵循的示例仅(但未指定)一个重写规则。我通过这种方式添加了几个:

RewriteCond %{REQUEST_PATH} !-f
RewriteRule ^/application01/angular/(.*) /application01/angular/index.html
RewriteRule ^/application02/apps/(.*) /application02/apps/index.html

缺少重复“RewriteCond”指令和缺少添加“[L]”。它必须看起来像这样:

RewriteCond %{REQUEST_PATH} !-f
RewriteRule ^/application01/angular/(.*) /application01/angular/index.html [L]

RewriteCond %{REQUEST_PATH} !-f
RewriteRule ^/application02/apps/(.*) /application02/apps/index.html [L]

无论如何谢谢

© www.soinside.com 2019 - 2024. All rights reserved.