marcinbunsch-quick_serve 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/bin/qs +4 -1
- data/bin/quick_serve +2 -30
- data/lib/quick_serve.rb +92 -0
- data/quick_serve.gemspec +4 -8
- metadata +4 -4
data/README.rdoc
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
= quick_serve
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
quick_serve is a super-simple way of serving static files for development. It was made mainly for javascript development, but might have other uses.
|
|
4
4
|
|
|
5
5
|
= usage
|
|
6
6
|
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.2.0
|
data/bin/qs
CHANGED
data/bin/quick_serve
CHANGED
|
@@ -1,32 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
require 'rubygems'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
rescue LoadError
|
|
6
|
-
puts "quick_serve requires mongrel. Install it with gem install mongrel"
|
|
7
|
-
exit(1)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if ARGV.length == 0
|
|
12
|
-
puts "quick_serve: port not specified, using 3000"
|
|
13
|
-
PORT = 3000
|
|
14
|
-
else
|
|
15
|
-
PORT = ARGV[0]
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
HOST = '0.0.0.0'
|
|
19
|
-
DIR = '.'
|
|
20
|
-
|
|
21
|
-
config = Mongrel::Configurator.new :host => HOST, :port => PORT do
|
|
22
|
-
listener do
|
|
23
|
-
uri "/", :handler => Mongrel::DirHandler.new(DIR)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
trap("INT") { stop }
|
|
27
|
-
run
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
puts "quick_serve: Mongrel running on port #{PORT} current directory as docroot"
|
|
31
|
-
config.join
|
|
32
|
-
|
|
3
|
+
require 'quick_serve'
|
|
4
|
+
QuickServe.new.start
|
data/lib/quick_serve.rb
CHANGED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'mongrel'
|
|
3
|
+
rescue LoadError
|
|
4
|
+
puts "quick_serve requires mongrel. Install it with: gem install mongrel"
|
|
5
|
+
exit(1)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
class QuickServe
|
|
9
|
+
|
|
10
|
+
def initialize
|
|
11
|
+
@options = { :dir => '.', :port => 3000, :host => '0.0.0.0', :deamon => false }
|
|
12
|
+
parse
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def start
|
|
17
|
+
puts "quick_serve: Mongrel running on port #{@options[:port]} current directory as docroot"
|
|
18
|
+
begin
|
|
19
|
+
if @options[:deamon]
|
|
20
|
+
pid = fork do
|
|
21
|
+
captured_stdout = StringIO.new
|
|
22
|
+
old_stdout, $stdout = $stdout, captured_stdout
|
|
23
|
+
captured_stderr = StringIO.new
|
|
24
|
+
old_stderr, $stdout = $stdout, captured_stderr
|
|
25
|
+
serve
|
|
26
|
+
end
|
|
27
|
+
File.open(pidfile, 'w') {|f| f.write(pid) }
|
|
28
|
+
else
|
|
29
|
+
serve
|
|
30
|
+
end
|
|
31
|
+
rescue Errno::EADDRINUSE
|
|
32
|
+
puts "quick_serve: Port #{@options[:port]} is used by another process. Please specify other port using the -p option"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def serve
|
|
39
|
+
options = @options
|
|
40
|
+
config = Mongrel::Configurator.new :host => options[:host], :port => options[:port] do
|
|
41
|
+
listener do
|
|
42
|
+
uri "/", :handler => Mongrel::DirHandler.new(options[:dir])
|
|
43
|
+
end
|
|
44
|
+
trap("INT") { stop }
|
|
45
|
+
run
|
|
46
|
+
end
|
|
47
|
+
config.join
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def parse
|
|
51
|
+
require 'optparse'
|
|
52
|
+
OptionParser.new do |opts|
|
|
53
|
+
opts.banner = "Usage: qs [options]"
|
|
54
|
+
|
|
55
|
+
opts.on("-p PORT", "--port PORT", "Specify port") { |value| @options[:port] = value; }
|
|
56
|
+
opts.on("--dir DIRECTORY", "Specify directory to act as docroot") { |value| @options[:dir] = value; }
|
|
57
|
+
opts.on("--host HOST", "Specify host") { |value| @options[:host] = value; }
|
|
58
|
+
# opts.on("quit", "quit deamon (if present)") { quit }
|
|
59
|
+
opts.on("-q", "quit deamon (if present)") { quit }
|
|
60
|
+
opts.on("-d", "--deamon", "Run as a deamon process") { @options[:deamon] = true; }
|
|
61
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
|
62
|
+
puts opts
|
|
63
|
+
exit
|
|
64
|
+
end
|
|
65
|
+
end.parse!
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def quit
|
|
69
|
+
|
|
70
|
+
print "Stopping quick serve... "
|
|
71
|
+
die(" pid file not found") if !File.exists?(pidfile)
|
|
72
|
+
pid = File.read(pidfile)
|
|
73
|
+
begin
|
|
74
|
+
if Process.kill("INT", pid.to_i) == 1
|
|
75
|
+
puts ' ok'
|
|
76
|
+
File.delete(pidfile) if File.exist?(pidfile)
|
|
77
|
+
end
|
|
78
|
+
rescue Errno::ESRCH
|
|
79
|
+
puts ' not found'
|
|
80
|
+
end
|
|
81
|
+
exit
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def pidfile
|
|
85
|
+
File.join(@options[:dir], "qs.#{@options[:port]}.pid")
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def die(msg)
|
|
89
|
+
puts msg
|
|
90
|
+
exit(1)
|
|
91
|
+
end
|
|
92
|
+
end
|
data/quick_serve.gemspec
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
# Generated by jeweler
|
|
2
|
-
# DO NOT EDIT THIS FILE
|
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
|
4
1
|
# -*- encoding: utf-8 -*-
|
|
5
2
|
|
|
6
3
|
Gem::Specification.new do |s|
|
|
7
4
|
s.name = %q{quick_serve}
|
|
8
|
-
s.version = "0.
|
|
5
|
+
s.version = "0.2.0"
|
|
9
6
|
|
|
10
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
8
|
s.authors = ["Marcin Bunsch"]
|
|
12
|
-
s.date = %q{2009-09-
|
|
9
|
+
s.date = %q{2009-09-12}
|
|
13
10
|
s.default_executable = %q{qs}
|
|
14
11
|
s.description = %q{}
|
|
15
12
|
s.email = %q{marcin@applicake.com}
|
|
@@ -31,11 +28,10 @@ Gem::Specification.new do |s|
|
|
|
31
28
|
"quick_serve.gemspec",
|
|
32
29
|
"test/test_helper.rb"
|
|
33
30
|
]
|
|
34
|
-
s.has_rdoc = true
|
|
35
31
|
s.homepage = %q{http://github.com/marcinbunsch/quick_serve}
|
|
36
32
|
s.rdoc_options = ["--charset=UTF-8"]
|
|
37
33
|
s.require_paths = ["lib"]
|
|
38
|
-
s.rubygems_version = %q{1.3.
|
|
34
|
+
s.rubygems_version = %q{1.3.3}
|
|
39
35
|
s.summary = %q{Super simple web server mainly for javascript development}
|
|
40
36
|
s.test_files = [
|
|
41
37
|
"test/test_helper.rb"
|
|
@@ -43,7 +39,7 @@ Gem::Specification.new do |s|
|
|
|
43
39
|
|
|
44
40
|
if s.respond_to? :specification_version then
|
|
45
41
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
46
|
-
s.specification_version =
|
|
42
|
+
s.specification_version = 3
|
|
47
43
|
|
|
48
44
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
49
45
|
else
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: marcinbunsch-quick_serve
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Marcin Bunsch
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-09-
|
|
12
|
+
date: 2009-09-12 00:00:00 -07:00
|
|
13
13
|
default_executable: qs
|
|
14
14
|
dependencies: []
|
|
15
15
|
|
|
@@ -35,7 +35,7 @@ files:
|
|
|
35
35
|
- lib/quick_serve.rb
|
|
36
36
|
- quick_serve.gemspec
|
|
37
37
|
- test/test_helper.rb
|
|
38
|
-
has_rdoc:
|
|
38
|
+
has_rdoc: false
|
|
39
39
|
homepage: http://github.com/marcinbunsch/quick_serve
|
|
40
40
|
licenses:
|
|
41
41
|
post_install_message:
|
|
@@ -60,7 +60,7 @@ requirements: []
|
|
|
60
60
|
rubyforge_project:
|
|
61
61
|
rubygems_version: 1.3.5
|
|
62
62
|
signing_key:
|
|
63
|
-
specification_version:
|
|
63
|
+
specification_version: 3
|
|
64
64
|
summary: Super simple web server mainly for javascript development
|
|
65
65
|
test_files:
|
|
66
66
|
- test/test_helper.rb
|