Module: Webhookdb::Apps

Defined in:
lib/webhookdb/apps.rb

Defined Under Namespace

Classes: API, AdminAPI

Constant Summary collapse

REDIRECTS =
{
  "/increase" => "/v1/install/increase",
}.freeze
Admin =
Rack::Builder.new do
  build_dir = Pathname(__FILE__).dirname.parent.parent + "admin-dist"
  dw = Rack::DynamicConfigWriter.new(build_dir + "index.html", global_assign: "window.whdbDynamicEnv")
  env = {
    "VITE_API_ROOT" => "/",
    "VITE_RELEASE" => "[email protected]",
    "NODE_ENV" => "production",
  }.merge(Rack::DynamicConfigWriter.pick_env("VITE_"))
  index_bytes = dw.as_string(env)
  Rack::SpaApp.run_spa_app(self, build_dir, enforce_ssl: Webhookdb::Service.enforce_ssl, index_bytes:)
end
SidekiqWeb =
Rack::Builder.new do
  use Sentry::Rack::CaptureExceptions if Webhookdb::Sentry.enabled?
  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(Webhookdb::Async.web_username),
    ) & Rack::Utils.secure_compare(
      ::Digest::SHA256.hexdigest(password),
      ::Digest::SHA256.hexdigest(Webhookdb::Async.web_password),
    )
  end
  use Rack::Session::Cookie, secret: Webhookdb::Service.session_secret, same_site: true, max_age: 86_400
  run Sidekiq::Web
end
Webterm =
Rack::Builder.new do
  use(Rack::SslEnforcer, {redirect_html: false}) if Webhookdb::Webterm.enforce_ssl
  use Rack::Deflater
  use Rack::ConditionalGet
  use Rack::ETag
  map "/" do
    use Webhookdb::Webterm::RedirectIndexHtmlToRoot
    use Webhookdb::Webterm::ServeIndexHtmlFromRoot
    run Webhookdb::Webterm::Files
  end
end

Class Method Summary collapse

Class Method Details

.rack_up(config_ru) ⇒ Object

Call this from your rackup file, like config.ru.

lib = File.expand_path(“lib”, __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require “webhookdb” Webhookdb.load_app require “webhookdb/apps” Webhookdb::Apps.rack_up(self)



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/webhookdb/apps.rb', line 53

def self.rack_up(config_ru)
  Webhookdb::Async.setup_web
  config_ru.instance_exec do
    map "/admin_api" do
      run Webhookdb::Apps::AdminAPI.build_app
    end
    map "/admin" do
      run Webhookdb::Apps::Admin.to_app
    end
    map "/sidekiq" do
      run Webhookdb::Apps::SidekiqWeb.to_app
    end
    map "/terminal" do
      run Webhookdb::Apps::Webterm.to_app
    end
    use Rack::SimpleRedirect, routes: (REDIRECTS.each_with_object({}) do |(k, v), memo|
      memo[k] = v
      memo["#{k}/"] = v
    end)
    run Webhookdb::Apps::API.build_app
  end
end