【发布时间】:2020-02-21 02:43:36
【问题描述】:
我将 Angular Universal 应用部署到生产服务器。我用 PM2 运行它,它可以工作。但是,它不运行应用程序的通用端。当我查看网页的页面源时,我看不到内容,而是 app-root 标记。
就好像 PM2 通过执行“ng serve”启动常规 Angular,而不是为 Angular Universal 执行“npm run serve:ssr”。
这是我的 package.json 和脚本的(一部分)。我是否必须将 'npm run serve:ssr' 放在这里的某个地方,以便在我调用 'PM2 start server.js' 时运行此命令?
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"compile:server": "webpack --config webpack.server.config.js --progress --colors",
"serve:ssr": "node server",
"build:ssr": "npm run build:client-and-server-bundles && npm run compile:server",
"build:client-and-server-bundles": "ng build --prod && ng run AppName:server:production --bundleDependencies all"
}
更新
因为我收到 403 错误,所以我让网络主机将 Apache 的文档根目录设置为浏览器文件夹,因为那是 index.html 所在的位置。这是否可能导致它无法加载应用程序的通用端的问题?因为它现在没有看到服务器文件夹?这是我的文件夹结构的样子:
domains
- appname.com
- public_html
- browser (=> this is the document root)
- index.html
- .htaccess
- other files...
- server
- server.js
- package.json
还有我的 .htaccess 文件:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /index.html [NC,L]
</IfModule>
【问题讨论】:
标签: angular pm2 angular-universal