Module: Roda::RodaPlugins::Proxy
- Defined in:
- lib/roda/proxy.rb
Overview
Roda plugin for simple API proxying
Defined Under Namespace
Modules: RequestMethods
Class Method Summary collapse
-
.configure(app, opts = {}) ⇒ Object
Respond to the configure method to set the destination when proxying Expects the following options: [to] Required.
Class Method Details
.configure(app, opts = {}) ⇒ Object
Respond to the configure method to set the destination when proxying Expects the following options:
- to
-
Required. The scheme and host of the proxy. Should not end with a slash.
- path_prefix
-
Optional. The path to append to the above for proxying.
The current request path will be prefixed on to this value.
Should begin and end with a +/+. Defaults to +/+.
For example, if the path prefix is +/foo/+ and the request received
by Roda is +GET /postcode/lookup+, The proxied request will be dispatched
to +GET /home/postcode/lookup+
Example:
plugin :proxy, to: 'https://foo.bar', path: '/my/api'
24 25 26 27 28 29 |
# File 'lib/roda/proxy.rb', line 24 def self.configure(app, opts = {}) app.opts[:proxy_to] = opts.fetch(:to, nil) app.opts[:proxy_path] = opts.fetch(:path_prefix, '/') raise 'Proxy host not set, use "plugin :proxy, to: http://example.com"' unless app.opts[:proxy_to] end |