代理http请求与节点 [英] proxy http request with node
问题描述
我在一个域上有一个nodeJs前端,在另一个域上有一个后端服务器。
我想能够从前面执行ajax请求到后面。因此,我打算使用反向代理,为了绕过相同的源策略限制。
我的后端Rest服务器将使用基本验证或OAuth 。我想知道,如果我使用node-http-proxy如果在代理它之前可以在http请求中发送授权头,以及如何。
谢谢很多。
有很多方法可以实现这一点:
-
您可以使用node-http-proxy中间件设置反向代理中的auth标头: http://blog.nodejitsu.com/http-proxy-middlewares
-
您可以要求http -proxy模块,创建一个新实例,然后使用所有可用的事件。
-
Fork node-http-proxy并修补您的版本http-proxy.js include custom custom_auth;
-
卷动您自己的逆向Proxy。使用node.js很安静,请查看这篇文章:
http:// www.catonmat.net/http-proxy-in-nodejs/
最好的问候, p>
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.
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,
这篇关于代理http请求与节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!