Class: Wurk::ExtensionsController

Inherits:
DashboardController show all
Defined in:
app/controllers/wurk/extensions_controller.rb

Overview

Serves third-party Web extensions (#187): ‘ext/:name/*subpath` runs the registered extension’s matched route and returns its rendered HTML for the SPA’s Extension page to embed; ‘ext-assets/:name/*file` serves files from the extension’s ‘asset_paths`.

Inherits DashboardController so an /ext/* URL that is actually the SPA’s client-side route (no extension registered under that name — e.g. a browser refresh on /wurk/ext/<tab>/) falls through to the SPA shell instead of 404.

Constant Summary

Constants inherited from DashboardController

DashboardController::INDEX_REL_PATH, DashboardController::VITE_ASSET_BASE, DashboardController::VITE_DEV_HOST, DashboardController::VITE_DEV_URL

Instance Method Summary collapse

Methods inherited from DashboardController

#index

Instance Method Details

#assetObject



31
32
33
34
35
36
37
# File 'app/controllers/wurk/extensions_controller.rb', line 31

def asset
  file, cache_for = Web::Extension::Renderer.asset_file(params[:name], params[:file])
  return head :not_found unless file

  response.headers['Cache-Control'] = "public, max-age=#{cache_for}"
  send_file file, disposition: 'inline'
end

#showObject



21
22
23
24
25
26
27
28
29
# File 'app/controllers/wurk/extensions_controller.rb', line 21

def show
  result = Web::Extension::Renderer.call(
    name: params[:name], method: request.request_method,
    subpath: "/#{params[:subpath]}", env: request.env, mount: request.script_name
  )
  return index unless result # not an extension → SPA client route; let React handle it

  respond_with(result)
end