1

Hi I have two process

  1. Django and MYSQL
  2. node/express and mongo db.

1.

How can I configure this two process to point to different url like. Django point to api.abc.com/v1 and node point to api.abc.com/v2 ?

2.

all my user login is inside Django and MYSQL with OAuth. I can authenticate user in Django.

But how can authenticate user in nodejs app with the token send by Django REST OAuth ?

Thanks.

Karesh A
  • 1,731
  • 3
  • 22
  • 47

2 Answers2

3

You can do it in few ways but the most convenient method would be to use a reverse proxy like nginx.

Configuring the reverse proxy for your Node app and doing exactly the same for your Django app will let you easily have the routes that you require, on the same domain name and port number just in a different path.

Another option would be to proxy requests either from the Node app to the Django app or the other way around, but that would require changing your applications instead of just putting a proxy in front of them.

Here are some questions with onfo on how to configure reverse proxies for Node using nginx, Apache and even Microsoft IIS:

Community
  • 1
  • 1
rsp
  • 107,747
  • 29
  • 201
  • 177
  • Hi. Yes I can run two different process on two different machine inside private network and configure NGINX reverse proxy like you have mentioned. What the best way to check the user credential of Django process (MYSQL) inside nodejs process ? – Karesh A Apr 06 '17 at 12:06
1

Scenario A

You create a url in django ^v2/.*$ and then make a request from django view to node.js process. this way django can handle user auth and permissions and node can be standalone and not know anything about user auth. If you need user data (id or something) you can inject it in the request as a header or a cookie.

Scenario B You dig into django REST OAuth implementation, find where tokens are stored in db, and on each request you take the oauth token from the header/cookie and compare it to the one in DB. You would have to setup nginx as a reverse proxy and route all traffic that goes on url /v1/.*$ to django app, and all traffic that goes to /v2/.*/ to node app.

Either options are doable but I would suggest Scenario A. It's easier, quicker and far less error prone.

J.D.
  • 1,145
  • 2
  • 15
  • 29
  • HI on some cases I need to call Django from Nodejs. Because our chat server is in node js. some cases user can directly call to django app and we call nodejs rest internally. ? – Karesh A Apr 06 '17 at 11:58
  • Yes, you just proxy the request from django to node. But I'm not sure if there is any point to upgrade connection to websocket protocol from django to node. Because, if I'm not mistaken, your client will have open TCP connection to nginx, nginx will have a connection to django and django will have a connection to node, all open. (Emphasize on if I'm not mistaken). If there is a need for open TCP connections (aka websockets) then go with the scenario B. But instead of digging in you can create an API route that will return true if the user is authenticated. – J.D. Apr 06 '17 at 13:59