 http = require 'http'
 fs = require 'fs'
+qs = require 'querystring'
     
 port = 8888
 

}

process.serve_url = (req, res) ->
#work out what resource the request is about
    file = req.url[1..]

    if req.method == 'PUT'
       #nasty hack, as we're only putting pages atm, and the URI's are :(
       file = file.replace(/^page\//, '')    #TODO: mmm, substring anyone?
       file = file.replace(/\/action$/, '')
    
    if file == ''
      console.log 'getting / == welcome-visitors.html topic'
      file = 'welcome-visitors.html'
      
    #TODO: security, don't allow non-topic id chars - avoid ../ etc
    file = file.replace(/\.\.[\/\\]/g, '')    #remove all instances of ../ and ..\ (talk about brutish and a tad simplistic
    file = file.replace(/\?.*$/i, '')     #remove ?random= - or other urlparams

          status = 404
        data = ""
      console.log 'status: '+ status
      #console.log ' contentType: '+ contentType
      if status is 200
          res.writeHead 200,
              'Content-Type': contentType
              'Content-Length': data.length + 1
          if encoding == 'binary'
            #console.log 'sending binary'
            res.write data, encoding
          else
            #console.log 'sending string'
            data = data.toString()
            res.write data + '\n'
          
