Module: Clacky::Server::ApiExtensionDispatcher
- Defined in:
- lib/clacky/extension/dispatcher.rb
Overview
Routes /api/ext/
Constant Summary collapse
- MOUNT_PREFIX =
"/api/ext/"
Class Method Summary collapse
-
.handle(req, res, http_server:) ⇒ Object
Public entry called from HttpServer#_dispatch_rest.
-
.public_path?(path, method) ⇒ Boolean
Tells HttpServer whether a given /api/ext/...
Class Method Details
.handle(req, res, http_server:) ⇒ Object
Public entry called from HttpServer#_dispatch_rest. Returns true to indicate the request was handled (200/4xx/5xx).
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/clacky/extension/dispatcher.rb', line 19 def handle(req, res, http_server:) mount_id, sub_path = parse_path(req.path) return not_found(res, "extension mount id missing") unless mount_id # Lazily (re)load the handler on each request so edits to handler.rb take # effect with no restart — cheap for a local app with a handful of exts. Clacky::ApiExtensionLoader.ensure_fresh(mount_id) klass = Clacky::ApiExtension.registry[mount_id] return not_found(res, "extension '#{mount_id}' not found") unless klass method = req.request_method.to_s.downcase.to_sym route, params = find_route(klass, method, sub_path) return not_found(res, "no route for #{req.request_method} #{req.path}") unless route # Public-endpoint check is done at HttpServer level (it owns access-key # logic); by the time we get here, auth has already been resolved. timeout_sec = route.[:timeout] || klass.class_timeout || Clacky::ApiExtension::DEFAULT_TIMEOUT invoke_route(klass, route, params, req, res, http_server, timeout_sec) true end |
.public_path?(path, method) ⇒ Boolean
Tells HttpServer whether a given /api/ext/... path can skip access-key auth, so the host can keep its single-source-of-truth auth logic.
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/clacky/extension/dispatcher.rb', line 44 def public_path?(path, method) mount_id, sub_path = parse_path(path) return false unless mount_id klass = Clacky::ApiExtension.registry[mount_id] return false unless klass return false if klass.public_paths.empty? route, _params = find_route(klass, method.to_s.downcase.to_sym, sub_path) return false unless route klass.public_paths.include?(route.pattern) end |