Django and Node processes for the same domain

白昼怎懂夜的黑 提交于 2019-12-19 10:52:25

问题


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.


回答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.




回答2:


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:

  • NGINX Reverse Proxy Causes 502 Errors On Some Pages
  • reverse proxy using ngix and ssl implementation on express failed
  • SSL With node / IIS
  • Adding chat through websocket, to an existing PHP web app
  • Where do I put my Node JS app so it is accessible via the main website?
  • How to run nodejs server over 443 ensuring nginx doesnt stop working
  • Configuring HTTPS for Express and Nginx


来源:https://stackoverflow.com/questions/43253823/django-and-node-processes-for-the-same-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!