JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
load common.coffe into client
authorJason Woofenden <jason@jasonwoof.com>
Thu, 27 Oct 2011 00:14:20 +0000 (20:14 -0400)
committerJason Woofenden <jason@jasonwoof.com>
Thu, 27 Oct 2011 00:14:20 +0000 (20:14 -0400)
index.html
server.coffee

index fc6742c..7322952 100644 (file)
@@ -9,6 +9,7 @@
        <script src="/javascript/jquery-ui/ui/jquery.ui.widget.js"></script>
        <script src="/javascript/jquery-ui/ui/jquery.ui.mouse.js"></script>
        <script src="/javascript/jquery-ui/ui/jquery.ui.draggable.js"></script>
+       <script src="common.js"></script>
        <script src="client.js"></script>
 </head>
 <body>
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) ->