Class: Wurk::API::App
- Inherits:
-
Object
- Object
- Wurk::API::App
- Defined in:
- lib/wurk/api/app.rb
Overview
The machine-facing HTTP API. Plain Rack under lib/, with no reference to
Rails or the engine, so one implementation serves all three mounts:
engine-nested (<mount>/api/v1), separately mounted
(mount Wurk::API => '/wurk-api'), and standalone (run Wurk::API).
Nothing here hardcodes '/wurk'. Every URL the API emits is built from SCRIPT_NAME (Request#url_for) — the same mount-agnostic rule the SPA shell follows in dashboard_controller.rb.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(config: nil) ⇒ App
constructor
configis read on every request rather than captured, so a token registered after the first request still takes effect.
Constructor Details
#initialize(config: nil) ⇒ App
config is read on every request rather than captured, so a token
registered after the first request still takes effect. Injectable
because a test must be able to hand this app its own token table
instead of mutating the process-wide one.
33 34 35 36 37 |
# File 'lib/wurk/api/app.rb', line 33 def initialize(config: nil) @config = config @router = Router.new draw(@router) end |
Instance Method Details
#call(env) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/wurk/api/app.rb', line 39 def call(env) request = Request.new(env) # Stamped once, before anything reads it, so every handler sees the # same config the auth gate did — including a test's injected one. request.config = config response = handle(request) # HEAD is routed as GET, so the handler built a body it must not send. request.head? ? [response[0], response[1], []] : response end |