简体   繁体   中英

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?

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). You can run it on a node.js server/express but it's not mandatory.

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.

I guess, I'm mixing some concepts or have general misunderstanding of deployments of Angular Apps on Heroku.

No, You can also create a simple http-server and host the application. 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.

You can also redirect any https request on this server.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM