简体   繁体   English

我是否需要 node.js(快递)将 Angular 应用程序部署到 Heroku?

[英]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.

相关问题 如何在不使用Express的情况下将节点应用部署到heroku - How do I deploy node app to heroku without using Express 在node.js中,构建socket.io/express应用程序时需要http吗? - In node.js do I need http when building a socket.io/express app? 在 heroku 中部署 node.js / express / mongoDB ( with typescript ) - Deploy node.js / express / mongoDB ( with typescript ) in heroku Node.js 应用程序在本地运行,但在部署到 heroku 时出现应用程序错误 - Node.js app works locally but when deploy to heroku I get application error 在部署在 Heroku 上的 node.js + Express 应用程序中找不到 jQuery 文件 - jQuery file is not found in node.js + Express app deployed on Heroku 在Heroku Node.js / Express App上禁用HTTPS - Disable HTTPS on Heroku Node.js/Express App 由于出现神秘错误,我无法将node.js部署到Heroku - I cannot deploy node.js to Heroku due to a mysterious error Heroku Node.js(express.js)应用程序在本地运行,但在使用MongoDB时在heroku上失败 - Heroku Node.js (express.js) App Works Locally but failed on heroku when using MongoDB 如何使用Node.js服务器部署Angular 5应用 - How to deploy Angular 5 app with Node.js Server 为什么需要将Express服务器实例作为参数传递给Node.JS中的http模块? - Why do I need to pass an express server instance as a parameter to the http module in Node.JS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM