Mercurial > hg > nodescore
diff nodescore.js @ 73:0c3a2942ddee
now using express to server static content
author | Rob Canning <rc@kiben.net> |
---|---|
date | Sun, 29 Jun 2014 12:11:51 +0000 |
parents | 9af4250ff7d5 |
children | 3a2845e3156e |
line wrap: on
line diff
--- a/nodescore.js Sun Oct 27 01:49:58 2013 +0100 +++ b/nodescore.js Sun Jun 29 12:11:51 2014 +0000 @@ -14,7 +14,12 @@ , fs = require('fs') , static = require('node-static'); -/* +var argu = process.argv.splice(2); +var port = argu[0] +var www = argu[1] + +console.log(www, port) + var requirejs = require('requirejs'); requirejs.config({ @@ -24,26 +29,32 @@ nodeRequire: require, findNestedDependencies: true }); -*/ + // run webserver serving static html //////////////////////////////////////////// -var clientFiles = new static.Server('www'); -var httpServer = http.createServer( - function(request, response) { - request.addListener('end', function () { - clientFiles.serve(request, response, function (e, res) { - if (e && (e.status === 404)) { // If the file wasn't found - clientFiles.serveFile('/404.html', 404, {}, request, response); - }} +var express = require("express"), + app = express(), + //bodyParser = require('body-parser') + errorHandler = require('errorhandler'), + methodOverride = require('method-override'), + port = parseInt(process.env.PORT, 10) || port; -); - process.setMaxListeners(0); - }); - }); +app.get("/", function (req, res) { + res.redirect("/index.html"); +}); -httpServer.listen(8000); +app.use(methodOverride()); +//app.use(bodyParser()); +app.use(express.static(__dirname + '/' + www)); +app.use(errorHandler({ + dumpExceptions: true, + showStack: true +})); + +// Create a Node.js based http server on port 8080 +var server = require('http').createServer(app).listen(port); //////////////////////////////////////////// var pinging=0 @@ -54,7 +65,7 @@ // connect to websockets //////////////////////////////////////////// -io = sio.listen(httpServer) +io = sio.listen(server) , nicknames = {}; //var sequencer = require('./sequencer') @@ -319,4 +330,4 @@ }); exports.socket= io.sockets; -exports.httpServer = httpServer; +exports.httpServer = server;