forked from VersaHQ/sidekiq-rack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.ru
31 lines (26 loc) · 1.07 KB
/
config.ru
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require 'sidekiq'
require 'sidekiq/web'
require 'rack/ssl-enforcer'
require 'rack/session'
Sidekiq.configure_client do |config|
config.redis = {
url: ENV.fetch('REDIS_URL', 'redis://localhost:6379'),
size: 1
}
end
map '/' do
if ENV['SIDEKIQ_USERNAME'] && ENV['SIDEKIQ_PASSWORD']
use Rack::Auth::Basic, 'Protected Area' do |username, password|
# Protect against timing attacks: (https://codahale.com/a-lesson-in-timing-attacks/)
# - Use & (do not use &&) so that it doesn't short circuit.
# - Use digests to stop length information leaking
Rack::Utils.secure_compare(::Digest::SHA256.hexdigest(username),
::Digest::SHA256.hexdigest(ENV['SIDEKIQ_USERNAME'])) &
Rack::Utils.secure_compare(::Digest::SHA256.hexdigest(password),
::Digest::SHA256.hexdigest(ENV['SIDEKIQ_PASSWORD']))
end
end
use Rack::SslEnforcer if ENV['RACK_ENV'] == 'production'
use Rack::Session::Cookie, secret: File.read('.session.key'), same_site: true, max_age: 86_400
run Sidekiq::Web
end