Class: LinkIO::Rack::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/linkio/rack/middleware.rb

Overview

Rack middleware that serves the LinkIO endpoints without any framework. Mount it in a config.ru or any Rack app:

use LinkIO::Rack::Middleware, client: my_client
run MyApp

Requests it does not recognise are passed through to the wrapped app. Handled routes:

GET  /.well-known/apple-app-site-association
GET  /.well-known/assetlinks.json
GET  /link
GET  /pending-link
GET  /pending-link/:device_id
POST /track-referral
GET  /referrals/:referrer_id

Instance Method Summary collapse

Constructor Details

#initialize(app, client: nil) ⇒ Middleware

Returns a new instance of Middleware.

Parameters:



25
26
27
28
# File 'lib/linkio/rack/middleware.rb', line 25

def initialize(app, client: nil)
  @app = app
  @client = client
end

Instance Method Details

#call(env) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/linkio/rack/middleware.rb', line 30

def call(env)
  request = ::Rack::Request.new(env) if defined?(::Rack::Request)
  method = env["REQUEST_METHOD"]
  path = env["PATH_INFO"].to_s

  result = route(method, path, env, request)
  result ? result.to_rack : @app.call(env)
end