Dear Camping ninjas, I''ve been using Camping via bin/camping and reloading works as expected OK. What I have not been able to do is to correctly setup a Camping app with reloading support in a standard config.ru rack app. Thanks for your attention --Omar G?mez -- Follow me at: Twitter: http://twitter.com/omargomez Buzz: http://www.google.com/profiles/108165850309051561506#buzz
Magnus Holm
2010-Aug-01 11:36 UTC
Reloading in a standard config.ru rack app (Camping 2.0)
?Hol? Se?or G?mez! First of all: *Never* use the reloader in production. It''s sloooooow! And because config.ru is mostly used for production, the reloader isn''t enabled there. Why do you want to use the reloader in config.ru instead of bin/camping by the way? If you want custom middlewares, you can always do it like this: module App user Middleware end And you can change the server it uses by `camping -s thin`. Anyway, if you want to use Camping::Reloader, you can do something like this: require ''camping'' require ''camping/reloader'' reloader = Camping::Reloader.new(''hello.rb'') reloader.on_reload do |app| app.create if app.respond_to?(:create) end app = proc do |env| # Reload (if needed) at every request: reloader.reload! # Returns a hash of the apps: apps = reloader.apps # Get the first app: apps.values.first.call(env) # If you have several apps, you probably want to # mount them on different paths instead. end run app If you''re on *nix you can also use Shotgun (http://github.com/rtomayko/shotgun): require ''camping'' Shotgun.after_fork do Camping::Apps.each do |app| app.create if app.respond_to?(:create) end end require ''hello'' run Hello And run the app with: `shotgun config.ru`. Shotgun spawns your app in each own process at *every* request, so it''s like it''s automatically starting and stopping a server between each request. This means that it''s slower, but more "correct". Camping::Reloader keeps everything in the same process, and uses some Ruby magic to automatically remove objects and load files again. It work 90% of the times, but is faster (it only reloads when needed) and it also works on Windows. Good luck! // Magnus Holm 2010/8/1 Omar G?mez <omar.gomez at gmail.com>:> Dear Camping ninjas, > > I''ve been using Camping via bin/camping and reloading works as expected OK. > > What I have not been able to do is to correctly setup a Camping app > with reloading support in a standard config.ru rack app. > > Thanks for your attention > > --Omar G?mez > > -- > Follow me at: > Twitter: http://twitter.com/omargomez > Buzz: http://www.google.com/profiles/108165850309051561506#buzz > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list >
Philippe Monnet
2010-Aug-01 12:51 UTC
Reloading in a standard config.ru rack app (Camping 2.0)
Hi Omar, When I want to test using rackup instead of the Camping server I use the following config.ru assuming that myapp.rb has a MyApp module: gem ''camping'' , ''>= 2.0'' %w(rack activerecord camping camping/session camping/reloader ).each { | r | require r} reloader = Camping::Reloader.new(''myapp.rb'') app = reloader.apps[:MyApp] run app And when I need to mount static content I also add the following statements _before _"run app": use Rack::Reloader use Rack::Static, :urls => [ ''/css'', ''/css/images'' ''/images'', ''/js'' ], :root => File.expand_path(File.dirname(__FILE__)) Note that this only meant for local testing or in your staging environment (for example if you need to make a quick change while troubleshooting an issue). Philippe On 7/31/2010 6:12 PM, Omar G?mez wrote:> Dear Camping ninjas, > > I''ve been using Camping via bin/camping and reloading works as expected OK. > > What I have not been able to do is to correctly setup a Camping app > with reloading support in a standard config.ru rack app. > > Thanks for your attention > > --Omar G?mez >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/camping-list/attachments/20100801/4784e53c/attachment-0001.html>
Worked like a charm, Thanks a lot! On Sun, Aug 1, 2010 at 7:52 AM, <camping-list-request at rubyforge.org> wrote:> > Message: 8 > Date: Sun, 01 Aug 2010 06:51:52 -0600 > From: Philippe Monnet <ruby at monnet-usa.com> > To: camping-list at rubyforge.org > Subject: Re: Reloading in a standard config.ru rack app (Camping 2.0) > Message-ID: <4C556DE8.3040105 at monnet-usa.com> > Content-Type: text/plain; charset="iso-8859-1"; Format="flowed" > > ?Hi Omar, > > When I want to test using rackup instead of the Camping server I use the > following config.ru assuming that myapp.rb has a MyApp module: > > gem ''camping'' , ''>= 2.0'' > %w(rack activerecord camping camping/session camping/reloader ).each { | > r | require r} > reloader = Camping::Reloader.new(''myapp.rb'') > app = reloader.apps[:MyApp] > run app > > And when I need to mount static content I also add the following > statements _before _"run app": > > use Rack::Reloader > use Rack::Static, > ? ? :urls => [ ''/css'', > ? ? ? ? ? ? ? ? ? ? ''/css/images'' > ? ? ? ? ? ? ? ? ? ? ''/images'', > ? ? ? ? ? ? ? ? ? ? ''/js'' ], > ? ? :root => File.expand_path(File.dirname(__FILE__)) > > Note that this only meant for local testing or in your staging > environment (for example if you need to make a quick change while > troubleshooting an issue). > > Philippe > > On 7/31/2010 6:12 PM, Omar G?mez wrote: >> Dear Camping ninjas, >> >> I''ve been using Camping via bin/camping and reloading works as expected OK. >> >> What I have not been able to do is to correctly setup a Camping app >> with reloading support in a standard config.ru rack app. >> >> Thanks for your attention >> >> --Omar G?mez >> >-- Follow me at: Twitter: http://twitter.com/omargomez Buzz: http://www.google.com/profiles/108165850309051561506#buzz
David Susco
2010-Aug-02 13:19 UTC
Reloading in a standard config.ru rack app (Camping 2.0)
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? Dave 2010/8/1 Omar G?mez <omar.gomez at gmail.com>:> Worked like a charm, > > Thanks a lot! > > On Sun, Aug 1, 2010 at 7:52 AM, ?<camping-list-request at rubyforge.org> wrote: >> >> Message: 8 >> Date: Sun, 01 Aug 2010 06:51:52 -0600 >> From: Philippe Monnet <ruby at monnet-usa.com> >> To: camping-list at rubyforge.org >> Subject: Re: Reloading in a standard config.ru rack app (Camping 2.0) >> Message-ID: <4C556DE8.3040105 at monnet-usa.com> >> Content-Type: text/plain; charset="iso-8859-1"; Format="flowed" >> >> ?Hi Omar, >> >> When I want to test using rackup instead of the Camping server I use the >> following config.ru assuming that myapp.rb has a MyApp module: >> >> gem ''camping'' , ''>= 2.0'' >> %w(rack activerecord camping camping/session camping/reloader ).each { | >> r | require r} >> reloader = Camping::Reloader.new(''myapp.rb'') >> app = reloader.apps[:MyApp] >> run app >> >> And when I need to mount static content I also add the following >> statements _before _"run app": >> >> use Rack::Reloader >> use Rack::Static, >> ? ? :urls => [ ''/css'', >> ? ? ? ? ? ? ? ? ? ? ''/css/images'' >> ? ? ? ? ? ? ? ? ? ? ''/images'', >> ? ? ? ? ? ? ? ? ? ? ''/js'' ], >> ? ? :root => File.expand_path(File.dirname(__FILE__)) >> >> Note that this only meant for local testing or in your staging >> environment (for example if you need to make a quick change while >> troubleshooting an issue). >> >> Philippe >> >> On 7/31/2010 6:12 PM, Omar G?mez wrote: >>> Dear Camping ninjas, >>> >>> I''ve been using Camping via bin/camping and reloading works as expected OK. >>> >>> What I have not been able to do is to correctly setup a Camping app >>> with reloading support in a standard config.ru rack app. >>> >>> Thanks for your attention >>> >>> --Omar G?mez >>> >> > > -- > Follow me at: > Twitter: http://twitter.com/omargomez > Buzz: http://www.google.com/profiles/108165850309051561506#buzz > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list >-- Dave
Paul van Tilburg
2010-Aug-02 15:07 UTC
Reloading in a standard config.ru rack app (Camping 2.0)
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: paul at luon.net University of Technology, The Netherlands | JID: paul at luon.net>>> Using the Power of Debian GNU/Linux <<< | GnuPG key ID: 0x50064181