Hi!
On Mon, Aug 02, 2010 at 09:19:25AM -0400, David Susco wrote:
> On a somewhat related note. How do people handle static content in a
> development environment? Is there a way to make the camping server
> aware of the public/ directory and serve the files within it?
>
> What about in production? Is passenger smart enough to pass requests
> for files in public/ back to apache or is some further configuration
> required?
I think everyone uses some variant on the following controller:
class StaticX
MIME_TYPES = {'.css' => 'text/css',
'.js' => 'text/javascript',
'.jpeg' => 'image/jpeg',
'.jpg' => 'image/jpeg',
'.png' => 'image/png'}
def get(path)
@headers['Content-Type'] = MIME_TYPES[path[/\.\w+$/, 0]] || "text/plain"
unless path.include? ".."
@headers['X-Sendfile'] = (BASE_DIR + path).to_s
else
@status = "403"
"403 - Invalid path"
end
end
end
with declaring at top: BASE_DIR = Pathname.new(__FILE__).dirname + "public"
Given that passenger picks up Camping apps only if they have a "public"
subdirectory and a config.ru, it might make sense to create a
camping/static library for serving static data with auto-mime-type
detection and ship this with Camping. Serving static files seems to be
done often. What do you guys think?
N.B. I had to install Apache with Passenger and the xsendfile module, but then
it worked out of the box.
Kind regards,
Paul
--
PhD Student @ Eindhoven | email: [email protected]
University of Technology, The Netherlands | JID: [email protected]
>>> Using the Power of Debian GNU/Linux <<< | GnuPG key ID: 0x50064181
_______________________________________________
Camping-list mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/camping-list