Skip to content

Instantly share code, notes, and snippets.

@itsbth
Created January 1, 2012 03:35
Show Gist options
  • Select an option

  • Save itsbth/1546158 to your computer and use it in GitHub Desktop.

Select an option

Save itsbth/1546158 to your computer and use it in GitHub Desktop.
Uploaded by UploadToGist for Sublime Text 2
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