Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Make Rack comparable to middleman server #560

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
Owner

tdreyno commented Aug 8, 2012

An attempt to refactor our internals so Rack can also have access to the file watcher and reloading.

Any idea on when this will be merged?

Owner

tdreyno commented Sep 13, 2012

For 3.1. Which, as for any big release, requires that myself or @bhollis has a couple days downtime from real life/work to sew everything up.

Probably not before the end of September. This code isn't final or tested, but we could make a 3.1 github branch that you could use if necessary.

@bhollis bhollis and 1 other commented on an outdated diff Sep 15, 2012

middleman-core/lib/middleman-core/application.rb
@@ -26,7 +26,19 @@ class Application
define_hook :ready
class << self
-
+
+ # Create a new Class which is based on Middleman::Application
+ # Used to create a safe sandbox into which extensions and
+ # configuration can be included later without impacting
+ # other classes and instances.
+ #
+ # @return [Class]
+ def server(&block)
@bhollis

bhollis Sep 15, 2012

Owner

I'm still not 100% clear on the value of creating a new server class every time this is invoked. What's the idea behind that?

@tdreyno

tdreyno Sep 16, 2012

Owner

We can't unmixin extensions, so we need a clean class for each config.rb change.

@bhollis

bhollis Sep 16, 2012

Owner

Oh, of course. Maybe we could keep some pointer to "the current application" though, to make it easier to find, and only cycle in a new application when reloading.

Owner

bhollis commented Sep 15, 2012

I'll admit, the rack stuff still really confuses me. When does calling a method create a new thing vs. using some cached instance? When should I use class methods vs. instance methods? Maybe some better internal documentation would help straighten this out for me.

Owner

tdreyno commented Sep 16, 2012

I don't know either, I'm cargo-culting Sinatra.

collin commented Jan 6, 2013

I came looking for this feature and found this issue. So I'm probably just making a fool of myself here and missing on something. But I couldn't get this commit to work and ended up trying out this:

Seems to do what I wanted to do. Works with pow and is a teensy bit of code.

config.ru

require 'rubygems'
require 'bundler'
Bundler.setup
require 'middleman'
require 'middleman-core/preview_server'

module Middleman::PreviewServer
  def self.preview_in_rack
    @options = {}
    @app = new_app
    start_file_watcher
  end
end

Middleman::PreviewServer.preview_in_rack

run Middleman::PreviewServer.app

Looking more at the commit it looks like there is a more general refactor here, where I'm just leaning on the PreviewServer.

Owner

tdreyno commented Jan 6, 2013

Yeah, this is tracking a work-in-progress refactor.

Aupajo commented Jan 15, 2013

👍

Darep commented Jan 25, 2013

@collin that works wonderfully on pow! Thanks! 👍

@collin thanks and some additions to make bootstrap-sass, hamlbars and other gems work with middleman through rack like through cli:

require "rubygems"
require "middleman-core/load_paths"

Middleman.setup_load_paths

require "middleman-core"
require "middleman-core/preview_server"

module Middleman::PreviewServer
  def self.preview_in_rack
    @options = {  }
    @app = new_app
    start_file_watcher
  end
end

Middleman::PreviewServer.preview_in_rack
run Middleman::PreviewServer.app.class.to_rack_app

@tdreyno tdreyno closed this Apr 21, 2013

Is there a newer way to do this? This causes POW to hang indefinitely for me.

@1ndivisible
How about to pass the latency to @options like:

module Middleman::PreviewServer
  def self.preview_in_rack
    @options = { latency: 0.25 }
    @app = new_app
    start_file_watcher
  end
end

I have tested with puma looking works well.

Addng the latency works perfectly for me, thanks @zeroyonichihachi

timcheadle added a commit to rationalmeans/rationalmeans.com that referenced this pull request Feb 25, 2014

@tdreyno tdreyno deleted the super_rack branch Jun 20, 2014

upgrading to Middleman 3.4.0 required updating config.ru as instructed here

require 'rubygems'
require 'bundler/setup'
require 'middleman-core/load_paths'

Middleman.setup_load_paths

require 'middleman-core'
require 'middleman-core/preview_server'

class Middleman::PreviewServer
  def self.preview_in_rack
    @server_information = ServerInformation.new
    @options = {  }
    @app = new_app
    start_file_watcher
  end
end

Middleman::PreviewServer.preview_in_rack
run Middleman::PreviewServer.app.class.to_rack_app

with

@options = { latency: 0.25  }

@amirnissim amirnissim referenced this pull request in middleman/middleman-livereload Jan 5, 2016

Open

LiveReload is not reloading #76

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment