Sha256: 925fa0cde80148e040252a89d12a1d98d0c0806a4f2587aca0a12adde1099dcb

Contents?: true

Size: 958 Bytes

Versions: 1

Compression:

Stored size: 958 Bytes

Contents

require 'active_support/core_ext/string/starts_ends_with'
require 'rack'

module Massimo
  class Server
    class << self
      def start(site, port = 3000)
        Massimo::UI.say "massimo is serving your site at http://localhost:#{port}", :growl => true
        trap('INT') do
          Massimo::UI.say 'massimo is shutting down your server', :growl => true
          Rack::Handler::WEBrick.shutdown
        end
        
        app = Rack::Builder.new do
          use Rack::ShowExceptions
          run Massimo::Server.new(site)
        end
        Rack::Handler::WEBrick.run(app, :Port => port)
      end
    end
    
    def initialize(site)
      @site        = site
      @file_server = Rack::File.new(site.config.output_path)
      @watcher     = Massimo::Watcher.new(site)
    end
    
    def call(env)
      @watcher.process
      env['PATH_INFO'] << 'index.html' if env['PATH_INFO'].ends_with? '/'
      @file_server.call(env)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
massimo-0.7.0 lib/massimo/server.rb