在 Sinatra 中,有没有办法将请求转发到另一个应用程序? [英] In Sinatra, is there a way to forward a request to another app?

查看:39
本文介绍了在 Sinatra 中,有没有办法将请求转发到另一个应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做这样的事情:

I'm trying to do something like this:

class Dispatcher < Sinatra::Base
  def initialize
    @foo = Foo.new
  end

  get '/foo/*' do 
    @foo.call(params[:splat])
  end
end

因此 URL/foo/abc/def?xxx=yyy 就像使用/abc/def?xxx=yyy 调用 Foo 应用程序一样.

So that URL /foo/abc/def?xxx=yyy would be like calling the Foo app with /abc/def?xxx=yyy.

这看起来应该很容易,但我还没有看到任何例子.

This seems like it should be easy, but I haven't seen any example of it.

推荐答案

我最终在 Rack config.ru 文件中执行此操作:

I ended up doing this in a Rack config.ru file:

map "/abc" do
  run Foo.new('abc')
end

map "/def" do
  run Foo.new('def')
end

不完全是我想要的,但使我免于修改底层应用程序.

Not exactly what I wanted, but saves me from modifying the underlying app.

这篇关于在 Sinatra 中,有没有办法将请求转发到另一个应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆