lib/slinky/server.rb in slinky-0.4.1 vs lib/slinky/server.rb in slinky-0.4.2
- old
+ new
@@ -5,10 +5,13 @@
# Sets the root directory from which files should be served
def self.dir= _dir; @dir = _dir; end
# Gets the root directory from which files should be served
def self.dir; @dir || "."; end
+ def self.config= _config; @config = _config; end
+ def self.config; @config || {}; end
+
# Splits a uri into its components, returning only the path sans
# initial forward slash.
def self.path_for_uri uri
_, _, _, _, _, path, _, _ = URI.split uri
path[1..-1] #get rid of the leading /
@@ -19,11 +22,11 @@
if mf
if path = mf.process
serve_file resp, path.to_s
else
resp.status = 500
- resp.content = "Error compiling #{mf.source}"
+ resp.content = "Error compiling #{mf.source}\n"
end
else
not_found resp
end
resp
@@ -50,15 +53,15 @@
end
# Returns the proper response for files that do not exist
def self.not_found resp
resp.status = 404
- resp.content = "File not found"
+ resp.content = "File not found\n"
end
# Method called for every HTTP request made
def process_http_request
- @manifest = Manifest.new(Server.dir)
+ @manifest = Manifest.new(Server.dir, Server.config)
path = Server.path_for_uri(@http_request_uri)
file = @manifest.find_by_path(path)
resp = EventMachine::DelegatedHttpResponse.new(self)
if file.is_a? ManifestDir