Class: AmazonStaticSite::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/amazon_static_site/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(folder = ARGV[1] || './public') ⇒ Server

Returns a new instance of Server.



5
6
7
8
# File 'lib/amazon_static_site/server.rb', line 5

def initialize(folder = ARGV[1] || './public')
  require 'rack'
  @folder = folder.gsub(/\/$/, '')
end

Instance Attribute Details

#folderObject (readonly)

Returns the value of attribute folder.



3
4
5
# File 'lib/amazon_static_site/server.rb', line 3

def folder
  @folder
end

Instance Method Details

#start(host: '0.0.0.0', port: 8080) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/amazon_static_site/server.rb', line 10

def start(host: '0.0.0.0', port: 8080)
  handler = Rack::Handler::WEBrick
  app     = LocalStaticSite.new
  app.settings.public_folder = folder
  puts "Starting server on folder: #{app.settings.public_folder} on http://#{host}:#{port}".green
  handler.run app, Host: host, Port: port
end