proxy http request with node

人盡茶涼 提交于 2019-12-08 02:19:59

问题


I have a nodeJs front end on one domain and a rest back end server on another domain.

I would like to be able to perform ajax requests from the front to the back. So, i intend to use a reverse proxy for that, in order to bypass the same origin policy restriction.

My back end Rest server will be secured with Basic auth or OAuth. I would like to know, if i use node-http-proxy if it is possible to send an Authorization header in the http request before proxying it, and how.

Thanks a lot.


回答1:


You have plenty of ways to accomplish that:

  • You can use node-http-proxy middlewares to set the auth headers in the reverse proxy: http://blog.nodejitsu.com/http-proxy-middlewares

  • You can require the http-proxy module, create a new instance and then use all the available events.

  • Fork node-http-proxy and patch your version http-proxy.js to include custom basic_auth;

  • Roll your own reverse proxy. With node.js it's quiet easy, check this post: http://www.catonmat.net/http-proxy-in-nodejs/

Best Regards,



来源:https://stackoverflow.com/questions/10166277/proxy-http-request-with-node

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