use some Middleware only for specific Rack website

前端 未结 1 607
小蘑菇
小蘑菇 2021-01-26 08:27

I have a Rack server where I run multiple websites.

use Rack::Session::Cookie

app = lambda do |env|

  case

  # Kek Mobile
  when env[\'HTTP_HOST\'] =~ /mobi.k         


        
相关标签:
1条回答
  • 2021-01-26 09:09

    I believe the URLMap middleware will solve your problem, or at least put you on the right track.

    • Examples: http://blog.ninjahideout.com/posts/rack-urlmap-and-kicking-ass
    • Official docs: http://rack.rubyforge.org/doc/classes/Rack/URLMap.html

    As you can see, URLMap lets you supply a different middleware pipeline for each app:

    use Rack::Lint
    
    map "/" do
      use Rack::CommonLogger
      run our_test_app
    end
    
    map "/lobster" do
      use Rack::ShowExceptions
      run Rack::Lobster.new
    end
    

    From your example, it's clear that this will not work directly, since you are mapping based on the HTTP host. However, the official docs mention, "Support for HTTP/1.1 host names exists if the URLs start with http:// or https://." So, perhaps you can call map "http://mobi.kek.com" and map "http://fb.kek.com".

    Good luck!

    0 讨论(0)
提交回复
热议问题