2016-04-20 16 views
7

Sto utilizzando un server websocket tootallnate che ascolta le connessioni da un sito Web.

Come si effettua una connessione al server su heroku?

Quando il mio sito web tenta di connettersi a

wss://Heroku-Name-39329.herokuapp.com/ 

o

wss://Heroku-Name-39329.herokuapp.com:5000/ 

mio Heroku registri di 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= 

e poi (ancora 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 

miei registri di javascript

WebSocket connection to 'wss://Heroku-Name-39329.herokuapp.com/:5000/' failed: Establishing a tunnel via proxy server failed. 

mie applicazioni fissati all'interno del server sono.

String host = ""; 
int port = 5000; 

mio Procfile

web: java $JAVA_OPTS -cp target/classes/:target/dependency/* v1.a1.server 

risposta

8

Provate ad usare questo:

String host = "0.0.0.0"; 
int port = System.getenv("PORT"); 

Su Heroku, è necessario associare ad 0.0.0.0 e utilizzare la porta assegnata per la vostra applicazione, che è contenuta nel $PORT variabile d'ambiente.

Dal client, non è necessario specificare una porta, pertanto è necessario utilizzare solo wss://Heroku-Name-39329.herokuapp.com/ (non quello con 5000).

+0

Non so dove 0.0.0.0 è venuto da invece di 127.0.0.1, ma grazie! [heroku kb] (https://kb.heroku.com/why-is-my-node-js-app-crashing-with-an-r10-error) – reergymerej

8

Heroku vuole che tu usi una determinata porta.

Aggiungi questo al vostro Procfile per ottenere quella porta:

-Dserver.port=$PORT 

Così vostro sarebbe simile a questa: Procfile

web: java $JAVA_OPTS -Dserver.port=$PORT -cp target/classes/:target/dependency 
+0

Oh uomo, sto inviando un vero buon karma al tuo fianco , nella vita reale. Ho cercato di risolvere questo bug per 6 ore ora. – orange14

1

Heroku ha una propria variabile ENV per il numero di porta. usalo nel file server.js.

// included process.env PORT variable for herokus specific port needed to deploy 
const PORT = process.env.PORT || 8000; 

quindi se non si utilizza PORT verrà utilizzato 8000. heroku utilizzerà la variabile PORT. file di esempio completo:

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'); 
    }); 
Problemi correlati