[英]How do I proxy AJAX requests with Rack Middleware?
I'm developing a Rails application that uses an API backend for AJAX requests written with Sinatra. 我正在开发一个Rails应用程序,它使用API后端来处理用Sinatra编写的AJAX请求。
The API runs separately from Rails: API与Rails分开运行:
Rails: localhost:3000
Rails: localhost:3000
API: localhost:9393
API: localhost:9393
In production, we'll be proxying requests to the API with nginx. 在生产中,我们将使用nginx代理对API的请求。
The problem is that we don't have nginx in development mode, we're using thin. 问题是我们在开发模式下没有nginx,我们使用的是瘦身。 So I need some sort of Rack middleware that I can add in development mode to proxy the requests for me. 所以我需要某种Rack中间件,我可以在开发模式中添加它来代理我的请求。
Can someone give me an example of how to do this? 有人能给我一个如何做到这一点的例子吗?
Perhaps Rack::Proxy: 也许Rack :: Proxy:
http://coderack.org/users/cwninja/middlewares/18-rackproxy http://coderack.org/users/cwninja/middlewares/18-rackproxy
use Rack::Proxy do |req|
if req.path =~ %r{identify api request with regex here}
URI.parse("http://localhost:9393/#{req.fullpath}")
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.