I'm using a tootallnate websockets server listening for connections from a website.
When my website tries to connect at
wss://Heroku-Name-39329.herokuapp.com/
or
wss://Heroku-Name-39329.herokuapp.com:5000/
My heroku logs output.
at=error code=H10 desc="App crashed" method=GET path="/" host=wss://Heroku-Name-39329.herokuapp.com request_id=4afca002-2078-439c-85dc-ad6ef7db50d2 fwd="207.244.77.23" dyno= connect= service= status=503 bytes=
And then(Still Heroku Logs)
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch
Stopping process with SIGKILL
Process exited with status 137
State changed from starting to crashed
State changed from crashed to starting
Starting process with command `java $JAVA_OPTS -cp target/classes/:target/dependency/* v1.a1.server
My javascript logs
WebSocket connection to 'wss://Heroku-Name-39329.herokuapp.com/:5000/' failed: Establishing a tunnel via proxy server failed.
My Apps set within the server are.
String host = "";
int port = 5000;
My Procfile
web: java $JAVA_OPTS -cp target/classes/:target/dependency/* v1.a1.server
Heroku wants you to use a certain port.
Add this to your Procfile to get that port:
-Dserver.port=$PORT
So yours would look like this: Procfile
web: java $JAVA_OPTS -Dserver.port=$PORT -cp target/classes/:target/dependency
Try using this:
String host = "0.0.0.0";
int port = System.getenv("PORT");
On Heroku, you must bind to 0.0.0.0
and use the port assigned to your app, which is contained in the $PORT
environment variable.
From the client, you will not need to specify a port, so only wss://Heroku-Name-39329.herokuapp.com/
should be used (not the one with 5000).
Heroku has its own env variable for its port number. use this in the server.js file.
// included process.env PORT variable for herokus specific port needed to deploy
const PORT = process.env.PORT || 8000;
so if not using PORT it will use 8000. heroku will use the PORT variable. full file example:
const express = require('express');
const app = express();
const router = express.Router();
app.use(express.static('public'));
router.get('*',function(req, res) {
res.sendFile(path.join(__dirname, './public/index'));
});
included process.env PORT variable for herokus specific port needed to deploy
const PORT = process.env.PORT || 8000;
app.listen(PORT, function(err) {
if (err) {
console.log(err);
return;
}
console.log('listening on port 8000');
});
Into application.properties
add:
server.port=${PORT:8080}
then into Procfile:
web: java $JAVA_OPTS -jar target/MyApp-0.0.1-SNAPSHOT.jar -Dserver.port=$PORT $JAR_OPTS
This should be enought.
I might be late to the party but this helped me solve this problem, change the application-prod.yml and bootstrap-prod.yml to reflect the heroku registry location and add -Dserver.port=$PORT to the Proc file after the $JAVA_OPTS , then relaunch! :)
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.