Class: Siru::Server

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

Instance Method Summary collapse

Constructor Details

#initialize(site, options = {}) ⇒ Server

Returns a new instance of Server.



3
4
5
6
7
8
9
# File 'lib/siru/server.rb', line 3

def initialize(site, options = {})
  @site = site
  @options = options
  @port = options[:port] || 3000
  @watch = options[:watch] || false
  @output_dir = 'public'
end

Instance Method Details

#startObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/siru/server.rb', line 11

def start
  puts "Starting Siru server on port #{@port}..."
  
  # Build the site initially
  builder = Builder.new(@site, @options)
  builder.build
  
  # Set up file watching if enabled
  setup_watcher if @watch
  
  # Start the web server
  server = WEBrick::HTTPServer.new(
    Port: @port,
    DocumentRoot: @output_dir,
    Logger: WEBrick::Log.new('/dev/null'),
    AccessLog: []
  )
  
  trap('INT') { server.shutdown }
  
  puts "Server running at http://localhost:#{@port}/"
  puts "Press Ctrl+C to stop"
  
  server.start
end