Sha256: 989f59cb60a5001742c378c85332f85e232badbda5f0a5c9ef39191b04ad8228

Contents?: true

Size: 870 Bytes

Versions: 11

Compression:

Stored size: 870 Bytes

Contents

require "rack"

module Sitepress
  # Evaluates a configuration file on each site request, then delegates to
  # a sitepres server for rednering. In a production environment, you'd want
  # to run `Sitepress::Server` directly.
  class PreviewServer
    DEFAULT_PORT = 8080
    DEFAULT_BIND_ADDRESS = "0.0.0.0".freeze

    def initialize(project:)
      @project = project
    end

    def run(port: DEFAULT_PORT, bind_address: DEFAULT_BIND_ADDRESS)
      # TODO: Move all of this junk into the PreviewServer class. Move
      # what's in there now into PreviewServer::Rack
      Rack::Handler::WEBrick.run rack_app,
        BindAddress: bind_address,
        Port: port do |server|
          Signal.trap "SIGINT" do
            server.stop
          end
      end
    end

    private
    def rack_app
      Proc.new { |env| @project.server.call(env) }
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
sitepress-cli-1.0.1 lib/sitepress/preview_server.rb
sitepress-cli-1.0.0 lib/sitepress/preview_server.rb
sitepress-cli-0.1.29 lib/sitepress/preview_server.rb
sitepress-cli-0.1.28 lib/sitepress/preview_server.rb
sitepress-cli-0.1.27 lib/sitepress/preview_server.rb
sitepress-cli-0.1.26 lib/sitepress/preview_server.rb
sitepress-cli-0.1.25 lib/sitepress/preview_server.rb
sitepress-cli-0.1.24 lib/sitepress/preview_server.rb
sitepress-cli-0.1.23 lib/sitepress/preview_server.rb
sitepress-cli-0.1.22 lib/sitepress/preview_server.rb
sitepress-cli-0.1.21 lib/sitepress/preview_server.rb