如何在子路径中部署角度通用?

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

我正在尝试将基本的角度通用应用程序部署到 /sub/ 文件夹。页面加载只是在该路径中找到,但 Angular 应用程序 js 文件却没有。

我已经使用启用 SSR 的 ng cli 设置了一个名为

subfold
的 Angular 17 应用程序。然后在
angular.json
文件中创建了如下构建配置:

"insub": {
  "baseHref": "/sub/"
}

和这样的服务配置:

"insub": {
  "buildTarget": "subfold:build:insub"
}

对于构建和服务,我使用这些命令:

ng build --configuration insub;
node PORT=4003 dist/subfold/server/server.mjs --configuration=insub;

在浏览器中访问

http://localhost:4003/sub/
,html 加载得很好,但
main.js
polyfill.js
文件无法加载。

这是 cli 的输出:

ERROR z [Error]: NG04002: 'main.js'

任何帮助表示赞赏, 谢谢

angular deployment server-side-rendering angular-universal
1个回答
0
投票

我找不到让 Express 引擎按预期工作的方法。但这里有一个使用 nginx 服务器的解决方法:

  location /sub/ {
    rewrite ^/sub/(.*) /$1 break;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://127.0.0.1:4000;
  }

请注意,重写规则省略了 url 的 /sub 部分,并且 proxy_pass 也设置为根 url 而不是 /sub 路径。

希望这会对某人有所帮助。 问候。

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