<?xml version="1.0" encoding="UTF-8"?>
<wiki>
  <body>&lt;p&gt;To serve static files, create a controller like this and put your static files in static/.&lt;/p&gt;
class Static &amp;lt; R &amp;#8216;/static/(.+)&amp;#8217;
MIME_TYPES = {
&amp;#8216;.html&amp;#8217; =&amp;gt; &amp;#8216;text/html&amp;#8217;,
&amp;#8216;.css&amp;#8217;  =&amp;gt; &amp;#8216;text/css&amp;#8217;,
&amp;#8216;.js&amp;#8217;   =&amp;gt; &amp;#8216;text/javascript&amp;#8217;,
&amp;#8216;.jpg&amp;#8217;  =&amp;gt; &amp;#8216;image/jpeg&amp;#8217;,
&amp;#8216;.gif&amp;#8217;  =&amp;gt; &amp;#8216;image/gif&amp;#8217;
}
&lt;span class=&quot;caps&quot;&gt;PATH&lt;/span&gt; = File.expand_path(File.dirname(&lt;code&gt;__FILE__&lt;/code&gt;))
def get(path)
@headers[&amp;#8216;Content-Type&amp;#8217;] = MIME_TYPES[path[/\.\w+$/, 0]] || &amp;#8220;text/plain&amp;#8221;
unless path.include? &amp;#8220;..&amp;#8221; # prevent directory traversal attacks
@headers[&amp;#8216;X-Sendfile&amp;#8217;] = &amp;#8220;#{PATH}/static/#{path}&amp;#8221;
else
@status = &amp;#8220;403&amp;#8221;
&amp;#8220;403 &amp;#8211; Invalid path&amp;#8221;
end
end
end
&lt;p&gt;This was originally from http://code.whytheluckystiff.net/camping/wiki/ServingStaticFiles .&lt;/p&gt;</body>
  <created-at type="datetime">2009-11-26T02:06:33-08:00</created-at>
  <id type="integer">300214</id>
  <permalink>serving-static-files</permalink>
  <repository-id type="integer">18311</repository-id>
  <title>Serving Static Files</title>
  <updated-at type="datetime">2009-08-20T15:15:24-07:00</updated-at>
  <user-id type="integer">117219</user-id>
</wiki>
