From: Magnus Holm <judofyr@gmail.com>
To: rack-devel <rack-devel@googlegroups.com>
Subject: Middleware for serving static files
Date: Tue, 20 Dec 2011 09:32:29 +0100 [thread overview]
Message-ID: <CAJ367fdCeAE8e3GgQsrj50w-k8GbhrV0ko4U5FQ5B=ara_JuqA@mail.gmail.com> (raw)
Problem:
I want to serve public/style.css as /style.css. How can I do this with
a middleware?
Rack::Static is out because it requires a prefix.
Rack::Cascade + Rack::File does the job, but Rack::Cascade doesn't
work as a middleware.
Any plans for either allowing Rack::Static to not use a prefix or make
Rack::Cascade work as a middleware too?
--
The reason I need it as a middleware is because Camping allows you to
inject middlewares in your application:
module MyApp
use Rack::Static
end
This is pretty nifty because you can keep everything on one file
(controllers, views, middlewares), but really breaks down because
there's no way to serve static files through a middleware.
Right now I'm using:
def (Before="").new(a,*o)Rack::Cascade.new(o<<a)end
module MyApp
use Before, Rack::File.new('public')
end
But it would certainly be better if Rack supported this by default…
next reply other threads:[~2011-12-20 8:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-20 8:32 Magnus Holm [this message]
2011-12-20 8:41 ` Middleware for serving static files Lee Hambley
2011-12-20 8:45 ` Magnus Holm
2011-12-20 8:52 ` Lee Hambley
2011-12-20 9:07 ` Magnus Holm
2011-12-21 2:49 ` James Tucker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://groups.google.com/group/rack-devel
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAJ367fdCeAE8e3GgQsrj50w-k8GbhrV0ko4U5FQ5B=ara_JuqA@mail.gmail.com' \
--to=rack-devel@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).