Sha256: 89ae491e7e5a4cdc58e2c68eaf00c7ecf71a7f27940e3e924f62b4bff60a3d9f

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

require 'bundler/setup'
require 'securerandom'

require 'clarion'

if ENV['RACK_ENV'] == 'production'
  raise 'Set $SECRET_KEY_BASE' unless ENV['SECRET_KEY_BASE']
end

if ENV['CLARION_DEV_HTTPS']
  use(Class.new do
    def initialize(app)
      @app = app
    end
    def call(env)
      @app.call env.merge('HTTPS' => 'on')
    end
  end)
end

config = {
  registration_allowed_url: Regexp.new(ENV.fetch('CLARION_REGISTRATION_ALLOWED_URL')),
  authn_default_expires_in: ENV.fetch('CLARION_AUTHN_DEFAULT_EXPIRES_IN', 300).to_i,
  app_id: ENV['CLARION_APP_ID'],
}

case ENV.fetch('CLARION_STORE', 's3')
when 's3'
  config[:store] = {
    kind: :s3,
    region: ENV.fetch('CLARION_STORE_S3_REGION'),
    bucket: ENV.fetch('CLARION_STORE_S3_BUCKET'),
    prefix: ENV.fetch('CLARION_STORE_S3_PREFIX'),
  }
when 'memory'
  config[:store] = {kind: :memory}
else
  raise ArgumentError, "Unsupported $CLARION_STORE"
end

case ENV.fetch('CLARION_COUNTER', nil)
when 'dynamodb'
  config[:counter] = {
    kind: :dynamodb,
    region: ENV.fetch('CLARION_COUNTER_DYNAMODB_REGION'),
    table_name: ENV.fetch('CLARION_COUNTER_DYNAMODB_TABLE'),
  }
when 'memory'
  config[:counter] = {kind: :memory}
when nil
  # do nothing
else
  raise ArgumentError, "Unsupported $CLARION_COUNTER"
end

use(
  Rack::Session::Cookie,
  key: 'clarionsess',
  expire_after: 3600,
  secure: ENV['RACK_ENV'] == 'production',
  secret: ENV.fetch('SECRET_KEY_BASE', SecureRandom.base64(256)),
)

run Clarion.app(Clarion::Config.new(config))

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
clarion-1.1.0 config.ru
clarion-1.0.0 config.ru