Created
January 1, 2012 03:35
-
-
Save itsbth/1546158 to your computer and use it in GitHub Desktop.
Uploaded by UploadToGist for Sublime Text 2
This file contains hidden or 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
| fs = require 'fs' | |
| connect = require 'connect' | |
| io = require 'socket.io' | |
| coffee = require 'coffee-script' | |
| coffee_cache = {} | |
| server = connect.createServer( | |
| connect.static(__dirname + '/public') | |
| (req, res, next) -> | |
| return next() unless m = req.url.match /^\/script\/([a-z0-9\/]+).coffee$/ | |
| fn = m[1] | |
| if fn of coffee_cache | |
| res.writeHead 200 | |
| res.end coffee_cache[fn] | |
| return | |
| fs.readFile "script/#{fn}.coffee", 'utf-8', (err, data) -> | |
| if err | |
| res.writeHead 404 | |
| res.end "404 Not Found" | |
| return | |
| coffee_cache[fn] = script = coffee.compile data | |
| res.writeHead 200, 'Content-Type': 'text/javascript' | |
| res.end script | |
| (req, res, next) -> | |
| res.writeHead 200 | |
| res.end "Hello, World!" | |
| ) | |
| io.listen server | |
| server.listen 8080 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment