From: Magnus Holm <judofyr@gmail.com>
To: rack-devel@googlegroups.com
Subject: Re: can I use Rack::Directory inside Rack::Builder block?
Date: Mon, 24 May 2010 22:16:15 +0200 [thread overview]
Message-ID: <AANLkTilvV4nxDx7eb1DGNo-pWgAhbQMmwxyttsMMS6mD@mail.gmail.com> (raw)
In-Reply-To: <p06240801c8206c949189@63.138.152.134>
Rack::Directory is an endpoint, not a middleware:
map "/cache" do
run Rack::Directory.new("cache")
end
// Magnus Holm
On Mon, May 24, 2010 at 19:56, Stephen Bannasch
<stephen.bannasch@deanbrook.org> wrote:
> At 3:18 AM -0400 5/24/10, Stephen Bannasch wrote:
>>I want to emulate a static web server with directory indexes using rack.
>>
>>Is there a way to use Rack::Directory inside a Rack::Builder block?
>
>
>
>
> The problem was that Rack::Directory#initialize:
> http://github.com/chneukirchen/rack/blob/master/lib/rack/directory.rb#L45
>
> expects arguments in a different order than Rack::Builder provides:
> http://github.com/chneukirchen/rack/blob/master/lib/rack/builder.rb#L53
>
>
> Here's what Rack::Directory#initialize looks like:
>
> module Rack
> class Directory
> def initialize(root, app=nil)
> @root = F.expand_path(root)
> @app = app || Rack::File.new(@root)
> end
> end
> end
>
>
> While Rack::Builder#use calls middleware like this:
>
> middleware.new(app, *args, &block)
>
> Here's my simple fix:
>
> module Rack
> class MyDirectory < Rack::Directory
> def initialize app, root
> super(root, app)
> end
> end
> end
>
>
> myapp = Rack::Builder.new do
> map "/" do
> use Rack::MyDirectory, 'cache'
> use Rack::Static, :urls => ["/"], :root => 'cache'
> run lambda {|env| [404, {}, '']}
> end
> end
>
> Should the middleware included with rack work with Rack::Builder#use ??
>
> There don't seem to be tests for this behavior.
>
> Would these tests be useful?
>
next parent reply other threads:[~2010-05-24 20:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <p06240801c81fd6be2bb9@192.168.1.106>
[not found] ` <p06240801c8206c949189@63.138.152.134>
2010-05-24 20:16 ` Magnus Holm [this message]
2010-05-25 0:42 ` can I use Rack::Directory inside Rack::Builder block? Stephen Bannasch
2010-05-25 1:14 ` James Tucker
2010-05-24 7:18 Stephen Bannasch
2010-05-24 17:56 ` Stephen Bannasch
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=AANLkTilvV4nxDx7eb1DGNo-pWgAhbQMmwxyttsMMS6mD@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).