-
Notifications
You must be signed in to change notification settings - Fork 277
Mounting Endpoints
Several Shrine plugins – upload_endpoint, presign_endpoint,
derivation_endpoint, and download_endpoint – come with Rack apps, which
can be "mounted" inside your router to handle incoming requests. Since these
apps are built on top of Rack, they can be used with any Rack-based Ruby web
framework.
Shrine.upload_endpoint(:cache)
Shrine.presign_endpoint(:cache)
Shrine.download_endpoint
Shrine.derivation_endpointHowever, different web frameworks offer a different API for mounting Rack apps. This document attempts to provide a comperhensive list of how this is done in all major Ruby web frameworks.
In Rails you can use #mount in config/routes.rb:
# config/routes.rb
Rails.application.routes.draw do
mount ImageUploader.derivation_endpoint => "derivations/image"
endSinatra doesn't offer an dedicated API, but you can still do it in your
config.ru:
# config.ru
map "/derivations/image" do
run ImageUploader.derivation_endpoint
end
run MyAppIn Hanami you can use #mount in config/environment.rb:
Hanami.configure do
mount ImageUploader.derivation_endpoint, at: "/derivations/image"
endIn Grape you can use #mount inside your app:
class MyApp < Grape::API
mount Shrine.derivation_endpoint => "/derivations/image"
endIn Roda you can use #run inside a routing tree:
class MyApp < Roda
route do |r|
r.on "derivations/image" do
r.run ImageUploader.derivation_endpoint
end
end
endIn Cuba you can use #run inside a routing tree:
class MyApp < Cuba
define do
on "derivations/image" do
run ImageUploader.derivation_endpoint
end
end
endIf your web framework doesn't support mounting Rack applications, you can
always mount it in your config.ru:
# config.ru
map "/derivations/image" do
run ImageUploader.derivation_endpoint
end
run MyApp