How to set Meteor WebSocket port for clients?

2019-05-30 19:53发布

问题:

How can I set the port WebSocket will be listening on? I'm trying to deploy Meteor on OpenShift, but there they have a nodejs-proxy server that listen on port 8000 instead 80, and redirect to my Meteor daemon. It is working since a manually created WebSocket object works fine.

I've set ROOT_URL but without success. It appears on the browser as defined bellow:

process.env.ROOT_URL = 'http://' + process.env.OPENSHIFT_APP_DNS + ':8000'

I'm using this quickstart: https://github.com/openshift-quickstart/openshift-meteorjs-quickstart. See file meteorshim.js for reference.

Everything works fine, including long-polling.

回答1:

I struggled with this for a while now and I tried different things. The solution that worked for me in OpenShift was this:

Set the DDP_DEFAULT_CONNECTION_URL variable

//for http
process.env.DDP_DEFAULT_CONNECTION_URL = 'http://' + process.env.OPENSHIFT_APP_DNS + ':8000'
//for ssl
process.env.DDP_DEFAULT_CONNECTION_URL = 'https://' + process.env.OPENSHIFT_APP_DNS + ':8443'

According to this blog post



回答2:

Just use the environmental variable PORT

so I guess:

process.env.PORT = 8000
process.env.ROOT_URL = 'http://' + process.env.OPENSHIFT_APP_DNS

To set websockets on a different port specifically and have meteor run on a different port I'm not too sure this is possible yet.