Module: Roda::RodaPlugins::BridgetownWebfinger::RequestMethods

Defined in:
lib/roda/plugins/bridgetown_webfinger.rb

Overview

Methods included in to the Roda request

Instance Method Summary collapse

Instance Method Details

#bridgetown_webfingervoid

This method returns an undefined value.

Builds the Webfinger route within the Roda application

Examples:

Enabling the Webfinger route


class RodaApp < Bridgetown::Rack::Roda
  plugin :bridgetown_ssr
  plugin :bridgetown_webfinger

  route do |r|
    r.bridgetown_webfinger
  end
end

Since:

  • 0.1.0



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/roda/plugins/bridgetown_webfinger.rb', line 56

def bridgetown_webfinger
  bridgetown_site = roda_class.opts[:bridgetown_site]

  on(".well-known/webfinger") do
    is do
      get do
        params = Bridgetown::Webfinger::Parameters.from_query_string(query_string)
        host = URI(bridgetown_site.config.url).host
        response["Access-Control-Allow-Origin"] =
          bridgetown_site.config.webfinger.allowed_origins

        unless (resource = params.resource)
          next response.webfinger_error("Missing required parameter: resource", status: 400)
        end

        if (jrd = webfinger_maybe_jrd(resource, host: host, params: params, site: bridgetown_site))
          response.webfinger_success(jrd)
        else
          response.webfinger_error("Unknown resource: #{resource}", status: 404)
        end
      end
    end
  end
end