Mel*_*emi 1 routing routes ruby-on-rails sidekiq
我知道这通常发生在控制器中,但我想知道是否有可能config/routes.rb限制基于特定IP(或IP范围)的路由?某种白名单,某种形式。
例如,我想将此路由限制为仅子网中的IP:
#config/routes.rb
require 'sidekiq/web'
MyApp::Application.routes.draw do
resources :users
...
mount Sidekiq::Web, at: "/sidekiq" # <== restrict this based on IP address
...
end
Run Code Online (Sandbox Code Playgroud)
根据Rails Docs中的示例,您可以执行以下操作:
#config/routes.rb
require 'sidekiq/web'
MyApp::Application.routes.draw do
resources :users
...
mount Sidekiq::Web, at: "/sidekiq", :constraint => Whitelist.new
...
end
class Whitelist
def initialize
@ips = Whitelist.retrieve_ips
end
def matches?(request)
@ips.include?(request.remote_ip)
end
def retrieve_ips
# get and return your whitelist of ips
end
end
Run Code Online (Sandbox Code Playgroud)
Yehuda Katz的这篇文章更详细地介绍了约束及其使用方法。
| 归档时间: |
|
| 查看次数: |
2143 次 |
| 最近记录: |