[英]Do I need node.js (express) to deploy an Angular App to Heroku?
Can I run my Angular App (build with ng build --prod
) only with node.js / express on Heroku?我可以仅使用 node.js / express 在 Heroku 上运行我的 Angular 应用程序(使用ng build --prod
)吗?
For my understanding, Angular in production does not need a node.js server but can run with only the generated static files (and some configuration).据我了解,生产中的 Angular 不需要 node.js 服务器,但只能使用生成的 static 文件(和一些配置)运行。 You can run it on a node.js server/express but it's not mandatory.您可以在 node.js 服务器/快递上运行它,但这不是强制性的。
So far, in most of the tutorials I found on Google regarding Deploying an Angular App on Heroku, the instructions always setup a server.js
file with express in the Angular app and there in the package.json
there is often something like a postinstall
or heroku-postbuild
script with a ng build --prod
command. So far, in most of the tutorials I found on Google regarding Deploying an Angular App on Heroku, the instructions always setup a server.js
file with express in the Angular app and there in the package.json
there is often something like a postinstall
or带有ng build --prod
命令的heroku-postbuild
脚本。
I guess, I'm mixing some concepts or have general misunderstanding of deployments of Angular Apps on Heroku.我想,我混淆了一些概念,或者对 Heroku 上的 Angular 应用程序的部署存在普遍误解。
No, You can also create a simple http-server and host the application.不,您还可以创建一个简单的 http-server 并托管应用程序。 However, this won't help you to understand how your application is being server.但是,这不会帮助您了解您的应用程序是如何成为服务器的。 Express-node server is a light weight and can help you define your routes. Express-node 服务器是轻量级的,可以帮助您定义路由。
You can also redirect any https request on this server.您还可以在此服务器上重定向任何 https 请求。
const forceSSL = function() {
return function (req, res, next) {
if (req.headers['x-forwarded-proto'] !== 'https') {
return res.redirect(
['https://', req.get('Host'), req.url].join('')
);
}
next();
}
}
app.use(forceSSL());
You can also use Docker to run angular app on Heroku.您还可以使用 Docker 在 Heroku 上运行 angular 应用程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.