I am currently developing a Rack-based application and want to redirect all file requests(e.g. filename.filetype) to a specified folder.
Rack::Static only supports file requests for a special folder(e.g. "/media").
Do I have to write an own Rack middleware or does a out-of-the-box solution exist?
Best regards
You might be able to use
Rack::File
directly. Here's aconfig.ru
file you can plug into rackup to see it work:To redirect every request to a particular path, use
Rack::File
(for some reason this class is absent in recent documentation, but it is still part of the latest Rack):To redirect every request, and add an HTML index of all files in the target dir, use
Rack::Directory
:To combine several directories or serve only a some requests from the target dir:
An update, the latest Rack implementation allows you to use Rack::Static
Example:
Will serve all static resources under
./media
folder relative toconfig.ru
location.