Skip to content

Commit

Permalink
Add WEBrick server to dev mode (closes #23)
Browse files Browse the repository at this point in the history
  • Loading branch information
winton committed Nov 7, 2011
1 parent 1b558d0 commit 6ecd8b3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bin/stasis
Expand Up @@ -6,7 +6,7 @@ gem "slop", "~> 2.1.0"
require 'slop'

slop = Slop.parse :help => true do
on :d, :development, "Development mode\t\t(auto-regenerate)"
on :d, :development, "Development mode\t\t(auto-regenerate)", :optional => true, :as => Integer
on :o, :only, "Only generate specific files\t(comma-separated)", :optional => true, :as => Array
on :p, :public, "Public directory path", :optional => true
on :s, :server, "Server mode\t\t\t(default redis host: localhost:6379/0)", :optional => true, :default => "localhost:6379/0"
Expand Down
24 changes: 23 additions & 1 deletion lib/stasis/dev_mode.rb
@@ -1,6 +1,9 @@
gem "directory_watcher", "~> 1.4.1"
require 'directory_watcher'

require 'logger'
require 'webrick'

class Stasis
class DevMode

Expand Down Expand Up @@ -31,7 +34,26 @@ def initialize(dir, options={})
dw.add_observer { render }
dw.start

loop { sleep 1000 }
if options[:development]
mime_types = WEBrick::HTTPUtils::DefaultMimeTypes
mime_types.store 'js', 'application/javascript'

server = WEBrick::HTTPServer.new(
:AccessLog => [ nil, nil ],
:DocumentRoot => @stasis.destination,
:Logger => WEBrick::Log.new("/dev/null"),
:MimeTypes => mime_types,
:Port => options[:development] || 3000
)

['INT', 'TERM'].each do |signal|
trap(signal) { server.shutdown }
end

server.start
else
loop { sleep 1000 }
end
end

private
Expand Down

1 comment on commit 6ecd8b3

@georgiee
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently there is no possibility to add other mime types like svg.
I`m now searching for a possibility to extend WEBrick::HTTPUtils::DefaultMimeTypes before stasis starts webrick.

Please sign in to comment.