How do I deploy an Angular.js app?

2019-03-15 02:05发布

This may be a stupid question, but I'm wondering what platform I should use to deploy my Angular.js app? I tried using Heroku but got a "no Cedar-supported app detected" error. Any thoughts?

UPDATE

I'm trying to serve this to heorku as a Node.js application, but still can't seem to get it working. There's a web-server.js file in the root directory of my application and I reference it in my Procfile here:

web: node web-server.js

And here's my package.json file, also in the root directory:

{
"name": "medicare-data",
"version": "0.0.1",
"dependencies": {
},
"engines": {
    "node": "0.10.x",
    "npm": "1.2.x"
},
"respository": "medicare-data",
"author": "sararob"
}

I'm getting a "slug compilation error" in my heroku logs. Thoughts on why this might not be working?

3条回答
干净又极端
2楼-- · 2019-03-15 02:25

I changed this line var DEFAULT_PORT = 8000; into: var DEFAULT_PORT = process.env.PORT || 8000;

..and then it worked. So I believe the reason is that heroku doesn't like your app running on port 8000.

查看更多
Root(大扎)
3楼-- · 2019-03-15 02:35

You can run an Angular app on heroku if it is served as a node.js application. Usually, when you start working with Angular seed, there is already a node webserver script in the project. I believe if there is a package.json file in the root, heroku will detect and run it as a node.js application. I'll come back and update this answer with more detail shortly.

UPDATE

From the Heroku docs (and I am no expert), it has this passage after the deploy section: https://devcenter.heroku.com/articles/nodejs#visit-your-application

which basically tells you to make sure you have one dyno running. You can do that either through the web app under the settings of your app or you can run this:

$ heroku ps:scale web=1

To see if the process is running, do

$ heroku ps
=== web: `node web.js`
web.1: up for 10s
查看更多
smile是对你的礼貌
4楼-- · 2019-03-15 02:35

I bet if you look at your logs you'll see something like this:

2013-08-26T12:51:18.257006+00:00 heroku[web.1]: Starting process with command `node scripts/web-server.js`
2013-08-26T12:51:19.109974+00:00 app[web.1]: Http Server running at http://localhost:8000/
2013-08-26T12:51:34.369092+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path=/ host=cmwidget.herokuapp.com fwd="77.101.66.230" dyno= connect= service= status=503 bytes=
2013-08-26T12:52:19.445974+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

It means that your Angular seed app is using it's own port (8000), and Heroku doesn't allow this. You need to relinquish the assignment of the port number to Heroku.

Easily fixed. Modify scripts/web-server.js, and change this:

this.server.listen(port);

...to this:

this.server.listen(process.env.PORT || port);
查看更多
登录 后发表回答