require 'phrender'
require 'embork/server'

class Embork::Phrender < Embork::Server

  def build_app
    cascade_apps = @cascade_apps
    phrender = [Phrender::RackMiddleware, {
      :javascript_files => @borkfile.phrender_javascript_paths,
      :javascript => @borkfile.phrender_raw_javascript,
      :index_file => @borkfile.phrender_index_file
    }]
    backend = @borkfile.backend
    Rack::Builder.new do
      use *phrender
      use backend unless backend == :static_index
      run Rack::Cascade.new(cascade_apps)
    end
  end

end

require 'phrender'
require 'embork/server'

class Embork::Phrender < Embork::Server

  def build_app
    cascade_apps = @cascade_apps
    phrender = [Phrender::RackMiddleware, {
      :javascript_files => @borkfile.phrender_javascript_paths,
      :javascript => @borkfile.phrender_raw_javascript,
      :index_file => @borkfile.phrender_index_file
    }]
    backend = @borkfile.backend
    cascade_apps.push backend if backend
    Rack::Builder.new do
      use *phrender
      run Rack::Cascade.new(cascade_apps)
    end
  end

end

Move the backend to the cascade apps
Move the backend to the cascade apps

- In dev mode, try sprockets, try static files, then try the back end,
  this eliminates some crazy hoops to jump through. None of the file
  generating apps needs to worry about calling up the stack, they can
  rely on headers that phrender sets.
