JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
load common.coffe into client
[peach-cgt.git] / server.coffee
index b3624ae..9beb901 100644 (file)
@@ -16,9 +16,20 @@ css_handler = (args, out, request, url_parts) ->
                        out.end css
 
 js_handler = (args, out, request, url_parts) ->
-       fs.readFile 'client.coffee', 'utf8', (err, data) ->
+       basename = url_parts.pathname.substr 1, (url_parts.pathname.length - 4)
+       if basename is 'client'
+               filename = 'client.coffee'
+       else if basename is 'common'
+               filename = 'common.coffee'
+       else
+               error = "Unknown js basename: #{basename}"
+               console.log error
+               out.end(error)
+               return
+
+       fs.readFile filename, 'utf8', (err, data) ->
                if err
-                       return out.end 'Server failed to read client.coffee'
+                       return out.end "Server failed to read #{filename}"
                out.end coffee.compile data
 
 html_handler = (args, out, request, url_parts) ->