Created
June 20, 2012 13:38
-
-
Save tiye/2959922 to your computer and use it in GitHub Desktop.
serve static pages up as if it's on server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/coffee | |
fs = require 'fs' | |
http = require 'http' | |
mime = require 'mime' | |
path = require 'path' | |
here = process.env.PWD | |
index = process.argv[2] | |
port = | |
if process.argv[3]? then Number process.argv[3] | |
else 8001 | |
http.createServer (req, res) -> | |
aim = req.url | |
if aim is '/' then aim = index | |
aim = path.join here, aim | |
console.log aim | |
if (path.existsSync aim) | |
fs.readFile aim, (err, file) -> | |
throw err if err? | |
res.writeHead 200, 'Content-Type': (mime.lookup aim) | |
res.end file | |
else res.end '' | |
.listen port | |
console.log 'listen port:', port |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment