Weinre on heroku - node.js

I am trying to set up Weinre on heroku but I am having some issues.
I manage to build the app, simply by using a package.json with weinre npm dependency and a Procfile that looks like the following
web: node_modules/weinre/weinre --httpPort $PORT
At first everything seems to work, the client shows up the UI, the JS file loads fine, but the debug does not work and no client ever shows up at the server side.
While looking at the logs, I realized that I keep getting 404 errors for every request that contains /ws/target/* or /ws/client/*
2012-05-31T22:37:53+00:00 heroku[router]: GET xxxx.herokuapp.com/target/target-script.js dyno=web.1 queue=0 wait=0ms service=10ms status=200 bytes=190900
2012-05-31T22:37:36+00:00 heroku[router]: GET xxxx.herokuapp.com/ws/target/t-3 dyno=web.1 queue=0 wait=0ms service=3ms status=404 bytes=9
2012-05-31T22:36:39+00:00 heroku[router]: POST xxxx.herokuapp.com/ws/client/c-1 dyno=web.1 queue=0 wait=0ms service=40ms status=404 bytes=9
This setup works localy with no problem.
I also tried the Procilfe with --boundHost 0.0.0.0 and got the same error. when I use my heroku app domain/subdomain as the host I got weinre: error running server: Error: listen EADDRNOTAVAIL error
If needed, you can checkout the source at the github repo
https://github.com/felipesabino/weinre-heroku
EDIT:
It is possible that it is related to WebSockets not being supported on Heroku:
https://devcenter.heroku.com/articles/http-routing#websockets
The weirdest thing is that the same issue happens with PhoneGap's weinre debug page as well
http://debug.phonegap.com/
Does anybody know how to solve this?

I have weinre running on Heroku at the moment but I remember that when I was trying to get it working it was a real nightmare.
This was using the 2.0.0-pre-H0WVARLU-incubating of weinre so it may be a bit different but what I had to do was:
Modify weinre itself, I had to tell weinre to bind to all hosts, I modified the cli.coffee file and I set the boundHost to -all- as the default
I commended out the if remoteAddress check in channelManager.coffee since the address you come in from is remapped through the proxy and was never matching
Turn on verbose debugging, while you don't actually need this to run it made it a lot easier to trace where errors are happening (and why the requests weren't routing)
My Procfile ended up being very simple as I tried to use weinre as "native" as possible (note the repo contains only weinre, it's not a module like you're doing):
web: node weinre
I left any port changes to be handled by process.env.PORT, not passed in from the Procfile
Basically what I found was that weinre really isn't designed to work behind a proxy!

See this pull request https://github.com/apache/incubator-cordova-weinre/pull/10
Note that no other modifications are needed, Procfile can set the options (like it should) and Weinre is properly used as node module.
package.json (that contains the fix)
"dependencies" : {
"weinre": "https://github.com/downloads/AppGyver/incubator-cordova-weinre/apache-cordova-weinre-2.0.0-pre-H77LBWIW-incubating-bin.tar.gz"
},
Procfile
web: node_modules/weinre/weinre --httpPort $PORT --boundHost -all- --debug true --verbose true

Modify weinre itself, I had to tell weinre to bind to all hosts, I modified the cli.coffee file and I set the boundHost to -all- as the default
I commended out the if remoteAddress check in channelManager.coffee since the address you come in from is remapped through the proxy and was never matching
this two Hints helped a lot on appfog, too
Also you need to
rename weinre to app.js
require local coffeescript
assign cli to a variable and execute run direct
extend cli.coffee - > Port with process.env.PORT

Related

Heroku nodejs app gets 503 error when connecting to heroku-redis

I have a nodejs API app running on heroku and i get a service unavailable 503 error when this app tries to connect to heroku-redis or another redis server on redislabs.com (I tried both redis servers to see if it'd make a difference). I have a free heroku dev account being used for this nodejs API app and the heroku-redis add-on. Perhaps I need a static IP for the free heroku app to connect to heroku-redis? Not sure.
This is what i see when i look at my app's logs on heroku:
2022-02-05T18:30:24.003600+00:00 app[web.1]: > start
2022-02-05T18:30:24.003601+00:00 app[web.1]: > node app.js
2022-02-05T18:30:24.003601+00:00 app[web.1]:
2022-02-05T18:30:26.254765+00:00 heroku[web.1]: State changed from starting to up
2022-02-05T18:31:03.724181+00:00 app[web.1]: Starting RXNsetup app
2022-02-05T18:31:03.725096+00:00 app[web.1]: Start Redis connection
2022-02-05T18:31:33.716830+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/run" host=rxnsetup.herokuapp.com request_id=c983d257-8773-4fff-a4d1-4b74341366b6 fwd="190.111.231.94" dyno=web.1 connect=0ms service=30176ms status=503 bytes=0 protocol=https
2022-02-05T18:30:00.000000+00:00 app[heroku-redis]: source=HEROKU_REDIS_CRIMSON addon=redis-symmetrical-62029 sample#active-connections=1 sample#load-avg-1m=1.105 sample#load-avg-5m=0.96 sample#load-avg-15m=0.6 sample#read-iops=0 sample#write-iops=0 sample#memory-total=15619136kB sample#memory-free=10625808kB sample#memory-cached=2390936kB sample#memory-redis=333744bytes sample#hit-rate=1 sample#evicted-keys=0
The first log statement above is in reference to another nodejs app that makes a POST HTTP request to the nodejs API app being run on heroku. I am able to connect to my redis server fine when i hit this same nodejs API app locally, but for some reason I get a 503 error when the same nodejs app runs in heroku. I have configured all of the same environment variables in heroku like i've done locally. I've been researching for awhile but am stuck with what could be causing this 503 error.
Update:
The root issue looked to be first that I had multiple instances of heroku-redis running, so I needed to promote one instance to be the primary one. Then another issue was that the REDIS_URL environment variable was being evaluated to undefined at runtime which was causing the 503 service errors I was getting.
I suspect you're looking at a stale connection string.
HEROKU_REDIS_<color> variables are normally only used if you have multiple deployments:
Heroku creates the REDIS_URL config var to store the location of the primary instance. In single-instance setups, your new instance is assigned a REDIS_URL. In cases where REDIS_URL exists, your instance is assigned a HEROKU_REDIS_<color> URL instead.
Normally, even if you have multiple instances, you would still connect to REDIS_URL, not HEROKU_REDIS_<color>. You can promote a HEROKU_REDIS_<color> URL to REDIS_URL by running
heroku redis:promote HEROKU_REDIS_<color>
Update your application to use REDIS_URL, review your addons to see if you have multiple Redis services provisioned, and decide which one(s) to keep. Then promote its variable to REDIS_URL as above.

How to make my app on Heroku stop timing out

I made a simple financial app consisting of a React frontend and Node/express backend that I want to deploy to Heroku. Since it's a small app I put everything (server as well as client files) in the root directory of my git repository. Thus the entry files for frontend (index.html), backend (index.js) and the Procfile required by Heroku are all in the root directory.
The server seems to be working fine, since I can successfully make requests from the locally installed frontend. However it appears that the server cannot serve the static files.
This is the log message from heroku:
2021-07-29T15:21:00.260957+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/" host=xpensoft.herokuapp.com request_id=2a484f4d-30cf-49b9-920d-14b9e9be28fb fwd="31.151.16.151" dyno=web.1 connect=0ms service=30000ms status=503 bytes=0 protocol=https
I am serving the static files using this server code:
if (process.env.NODE_ENV === 'production') {
app.use(express.static(__dirname));
}
Anyone has any idea what could be causing the timeout?
EDIT:
Apart from the code above, which is supposed to serve up the static files (which is unfortunately doesn't) there is no specific code in the server file handling the '/' endpoint. There is only code for specific named endpoints.
In the React app I am redirecting the user using React Router:
<Route exact path='/'>
<Redirect to='/user' />
</Route>
However the React app is never loaded.
request timeout error comes when your app takes more than 30 seconds to send a response back to the client.
So there is some issue with your code which handles the '/' route.
if Your static files are facing issues to get served up, it's most probably the issues with .env file. So manually add the enviorment variables in Heroku Settings > Config Vars

How do I deploy an Angular.js app?

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?
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
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);
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.

First Heroku deploy failed `error code=H10`

I deployed my app to Heroku. It's a node.js + express + socket.io app and this is the package.json file
{
"name": "game_test",
"author": "Ilya",
"description": "A test app for our board game",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app"
},
"dependencies": {
"express": "3.0.6",
"jade": "*",
"socket.io" : "*"
},
"engines": {
"node": "0.8.14"
}
}
This is the log I get:
heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=game-test-1.herokuapp.com fwd=37.26.146.185 dyno= queue= wait= connect= service= status=503 bytes=
heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=game-test-1.herokuapp.com fwd=37.26.146.185 dyno= queue= wait= connect= service= status=503 bytes=
What does it mean?
Found solution for me here: Heroku + node.js error (Web process failed to bind to $PORT within 60 seconds of launch)
In my case my app crashed because I was hard setting the PORT, instead of using the port that heroku dinamicaly sets, which can be accessed with process.env.PORT
app.listen(process.env.PORT || 3000, function(){
console.log("Express server listening on port %d in %s mode", this.address().port, app.settings.env);
});
I just had a similar issue with my app, I got the issue after a migration of the DB, after trying many options, the one that helped me was this:
heroku restart
(Using Heroku toolbelt for mac)
I had this issue, the only problem was my Procfile was like this
web : node index.js
and I changed to
web:node index.js
the only problem was spaces
In my case, i found same error because there is version difference of node and npm on my local machine and defined in package.json version.
"engines": {
"node": "0.8",
"npm": "1.2.x"
}
when i check using
node --version : v0.10.41
npm --version : 1.4.29
when i update my package.json to
"engines": {
"node": "0.10.41",
"npm": "1.4.29"
}
It works fine :)
in my case adding process.env.PORT || 3000 to my http server script, resolved.
My heroku log reported 'H20' error and 503 http status.
In my case there was no start command in the script section of package.json file.
When I created the package.json file with npm init I did not create a start script command.
So I went to the package.json file, under scripts I added a new entry:
"scripts": {
"start": "node index.js"
},
Saved it and uploaded to Heroku and it worked
In my case, my Procfile was pointing to the wrong file (bot.js which I previously used) so once I updated it, the error was gone.
Also check your database connection. I forgot to change my database connection from localhost and this crashed my app once it was pushed to heroku.
I faced this same problem and none of the answers above helped me.
What i did was run:
node --version
and in the package.json add the engines section with your node version:
{
"name": "myapp",
"description": "a really cool app",
"version": "1.0.0",
"engines": {
"node": "6.11.1"
}
}
upon using hapi18, I find taking out the "host" field and setting the port to:
port: process.env.PORT || 5000 did the trick.
Old Thread, but I fix this issue by setting PORT constant to process.env.PORT ||
For some weird reason, it wanted to search Env first.
I had a typo
const PORT = process.env.PORT||'8080';
used to be
const PORT = process.env.port||'8080';
If you locally start node server by nodemon, like I did, and it locally works, try npm start. Nodemon was telling me no errors, but npm start told me a lot of them in a understandable way and then I could solve them by following another posts here. I hope it helps to someone.
In my own case, i got this error because i refuse to add a Procfile to my node js app and my "main": "app.js" was initially pointing to another js file as main. so doing these chnages get it fixed for me
Password contained a % broke it for me.
In my case, I forgot to set database env for deployment.
you can set env by this command
(I'm using mLab for MongoDB server)
heroku config:set MONGO_URI='mongodb://address'
For me it was Package.json it was empty from dependencies even though i thought i did install them.. so I had to reinstall them with --save option in the end and verify they were added to the package.json.. and then push it again and it worked.
My port was set to config.httpPort which resolves to 80. I fixed it by doing this:
const PORT = process.env.PORT || config.httpPort;
app.listen(PORT, ...)
Thanks a lot, it wasted me a lot of hours last night.
In my case I had code=H10 and status=503 because my
Procfile:
web: node build/server.js
and I included /build in .gitignore
My start command had env-cmd -f ./config/prod.env node index.js.
after changing to: node index.js it got fixed.
I got the same issue, the problem was my Profile was like this:
web: gunicorn__init__:app
Notice with the above there was no space between gunicorn and __ init __
instead of
web: gunicorn __init__:app
in my case the problem solved by changing the order :
From :
app.listen(2000 || process.env.PORT);
to :
app.listen(process.env.PORT || 2000);
Just got this error and resolved it. For anyone who has tried the other methods and failed, do check your Procfile path. My server was in the backend folder yet I only typed web: node server.js. I resolved the error after changing it to web: node backend/server.js
The H10 error code could mean many different things. In my case, the first time was because I didn't know that Heroku isn't compatible with Sqlite3, the second time was because I accidentally pushed an update with Google analytics working in development as well as production.
I got the same above error as "app crashed" and H10 error and the heroku app logs is not showing much info related to the error msg reasons. Then I restarted the dynos in heroku and then it showed the error saying additional curly brace in one of the index.js files in my setup. The issue got fixed once it is removed and redeployed the app on heroku.
Older thread, but for me I didn't set my .env vars in the Heroku console.
i was using body-Parser that throw exception
const bodyParser = require('body-Parser')
//Bodyparser Middleware
app.use(bodyparser.json())
intead of using
//Bodyparser Middleware
app.use(express.json())
this resolved my issue
I want to register here what was my solution for this error which was a simple file not updated to Github.
I have a full stack project, and my files are structured both root directory for backend and client for the frontend (I am using React.js). All came down to the fact that I was mistakenly pushing the client folder only to Github and all my changes which had an error (missing a comma in a object's instance in my index.js) was not updated in the backend side. Since this Heroku fetches all updates from Github Repository, I couldn't access my server and the error persisted. Then all I had to do was to commit and push to the root directory and update all the changes of the project and everything came back to work again.
I struggle with the same error for hours, but I was able to solve it. I installed multer and aws-sdk as a devDependencies by mistake, instead of just dependencies.
So, anyone who has the same error, just double-check your package.json file.
Also, a small tip for the property of the engine in package.json.
enter code here
//The greater or equal operators will make sure that you use the right node
//version
//even if your current node is greater version than npm node
"engines": {
"node": ">= 0.8.14"
},
//insted of
"engines": {
"node": "0.8.14"
}
I was deploying python Django framework when I got this error because I forget to put my app name web: gunicorn plaindjango.wsgi:application --log-file - instead of plaindjango

Heroku Error H14 (No web processes running)

Pretty sure some people encountered this problem before.
Followed all the instructions to setup node and npm. When pushing to heroku there were no errors. But when I open the app, it shows "Application Error"
heroku ps
returns
Process State Command
------- --------- ------------
main.1 up for 1m node main.js
while
heroku logs
returns
Error H14 (No web processes running) -> GET mewtwo.herokuapp.com/ dyno= queue= wait= service= status=503 bytes=
I tried restarting the app with heroku restart but still get the same error. Google around and there were no other solution other than heroku restart. Anyone tried other methods ?
I had the same problem, but for me it was because I needed to run heroku ps:scale web=1
The name of your web process must be web, and this is the process that Heroku will always scale to '1' on initial deploy.
Other services in the Procfile can be called what you want, but you need to scale them initially (so you can have dev only processes in there if you want).
More information here: http://neilmiddleton.com/the-procfile-is-your-friend/
(the cached version: https://web.archive.org/web/20130926005616/http://www.neilmiddleton.com/the-procfile-is-your-friend)
I guess my problem was this, i had a python script in my node application which led heroku to believe that it is a python app, also i did not add a procfile since i expected the build bots to automatically detect that its a node app, so after setting up the procfile , then specifying the node and npm versions inside engines key in package.json, and changing the buildpack type to heroku/node, i got my app running.
Full disclosure, I solved this problem by turning it on.
Heroku Application Overview tab > click Configure Dyno > click the pencil icon > click toggle switch to On position > click confirm

Resources