Serving files inside of directories with ruby and mongrel
Posted
by AdamB
on Stack Overflow
See other posts from Stack Overflow
or by AdamB
Published on 2010-05-08T23:53:38Z
Indexed on
2010/05/08
23:58 UTC
Read the original article
Hit count: 411
I made a simple web server in Ruby using the Mongrel gem. It works great for files in a single directory, but I run into some path issues when inside a directory.
Lets say we have 2 files in a directory named "dir1", "index.html" and "style.css". If we visit http://host/dir1/index.html, the file is found, but style.css isn't because it's trying to load "style.css" from http://host/style.css instead of inside the directory.
index.html is trying to load style.css as if its in the same directory as itself.
<link href="style.css" rel="stylesheet" type="text/css" />
I can get the file if I enter the full path of style.css: /dir1/style.css but it doesn't seem to remember it's already inside a directory and that no path before a filename should serve from the current directory.
This is the ruby code im using to serve out files.
require 'rubygems'
require 'mongrel'
server = Mongrel::HttpServer.new("0.0.0.0", "3000")
server.register("/", Mongrel::DirHandler.new("."))
server.run.join
© Stack Overflow or respective owner