3

I have a django app on openshift and can't add node.js cartridge to it because of this then I decide to create another app in another host like heroku. I want to write this in html in client side (in django openshift app ) :

.....
<script src="{% static 'social/js/socket.io.js' %}"></script>
<script>
    var socket = io.connect('mynodejs.herokuapp.com', {port: 4000});
</script>

and in server side do this (in heroku app):

var http = require('http');
var server = http.createServer().listen(4000);

I mean I want connect two app one in openshift(django) and one in heroku(for node.js server). but this doesn't work on node.js server(heroku) and that port(4000) doesn't really listen to requests coming. I search this problem and find this helpful link in SO.now I know that process.env.PORT is dynamically change every time node.js run the script. but I can't access to that with url. I means if process.env.PORT equals to 9048 then I can't access to :

mynodejs.herokuapp.com:9048

how to access to a port externally in heroku. is it possible ?

Community
  • 1
  • 1
mojibuntu
  • 307
  • 3
  • 16

3 Answers3

0

I used to create server with Rails and Node.js. I used Redis as session store and shared session between two server (with a little tweak of session store gem/module for Ruby and Node.js).

Additionally, in order to invoke methods across different server, I also used pub/sub ability of Redis. For example, if you want to invoke a Node.js method from Django, you first subscribe a Redis channel in Node.js, then you publish a message to the same channel in Django (you can also send method arguments in the message). When Node.js received the message, methods you defined will be executed immediately.

Daiwei
  • 40,666
  • 3
  • 38
  • 48
0

You interface with Heroku apps always on port 80. The PORT variable is only internal to Heroku. It will forward any traffic from mynodejs.herokuapp.com(:80) to your app on port $PORT (process.env.PORT).

Baruch
  • 20,590
  • 28
  • 126
  • 201
0

My solution would be to instruct both servers listen on port 80 (standard practice). Then, add a custom token to each server environment containing the hostname of the other remote server that it needs to connect with.

Both servers should be able to contact each other on port 80.

You can run rhc env help for assistance when managing these custom tokens on OpenShift. Heroku has a similar mechanism for managing application secrets and keys.

ʀɣαɳĵ
  • 1,992
  • 1
  • 15
  • 20