Permalink
Browse files

Add beginning of ui

  • Loading branch information...
1 parent f68d968 commit bc911cab4c0670d9faacd3b80b7e1c6bc9933277 @creationix committed Feb 1, 2012
Showing with 56 additions and 0 deletions.
  1. +9 −0 server.lua
  2. +36 −0 static.lua
  3. +11 −0 ui/index.html
View
@@ -1,7 +1,16 @@
local Tcp = require('tcp')
+local Http = require('http')
+local Stack = require('stack')
local Emitter = require('emitter')
local JsonStream = require('./jsonstream')
local Json = require('json')
+local Path = require('path')
+
+-- An HTTP server for browsers to watch
+Http.create_server("0.0.0.0", 8080, Stack.stack(
+ require('./static')(Path.join(__dirname, "ui"), "index.html")
+))
+print("Http server listening at http://localhost:8080/")
-- A server for joystick clients to connect to
Tcp:create_server("0.0.0.0", 5000, function (socket)
View
@@ -0,0 +1,36 @@
+local Url = require('url')
+local FS = require('fs')
+local Path = require('path')
+local MIME = require('mime')
+
+return function (root, index)
+ return function (req, res, next)
+ if not req.method == "GET" then return next() end
+ req.uri = req.uri or Url.parse(req.url)
+ local path = Path.join(root, req.uri.pathname)
+ FS.stat(path, function (err, stat)
+ if err then
+ if err.code == "ENOENT" then
+ return next()
+ end
+ return next(err)
+ end
+ if index and stat.is_directory then
+ res:write_head(301, {
+ Location=Path.join(req.uri.pathname, index)
+ })
+ res:finish()
+ return
+ end
+ local stream = FS.create_read_stream(path);
+ stream:on('error', next)
+ stream:once('data', function ()
+ res:write_head(200, {
+ ["Content-Type"] = MIME.get_type(path),
+ ["Content-Length"] = stat.size
+ })
+ end)
+ stream:pipe(res)
+ end)
+ end
+end
View
@@ -0,0 +1,11 @@
+<!doctype html>
+<html>
+<head>
+ <title>JackDaddyGame</title>
+ <link rel="stylesheet" href="style.css"/>
+</head>
+<body>
+ <script src="client.js"></script>
+</body>
+</html>
+

0 comments on commit bc911ca

Please sign in to comment.