From e3c055f7d320ae19b93da9a09a9883ad94d14966 Mon Sep 17 00:00:00 2001 From: paulr Date: Sun, 23 Dec 2012 23:19:30 +1100 Subject: [PATCH] new request layout bits --- app.js | 10 ---------- lib/app.js | 36 ++++++++++++++++++++++++++++++++++++ lib/layouts.js | 18 ++++++++++++++++++ lib/wsrequest.js | 21 ++++++++++++++++----- 4 files changed, 70 insertions(+), 15 deletions(-) delete mode 100644 app.js create mode 100644 lib/app.js create mode 100644 lib/layouts.js diff --git a/app.js b/app.js deleted file mode 100644 index e357dab..0000000 --- a/app.js +++ /dev/null @@ -1,10 +0,0 @@ -var http = require("http"), - url = require("url"), - path = require("path"), - fs = require("fs"), - req = require("./lib/wsrequest.js"), - port = process.argv[2] || 8888; - -http.createServer(req.wsRequest).listen(port); - -console.log("Server running on port: ", port); \ No newline at end of file diff --git a/lib/app.js b/lib/app.js new file mode 100644 index 0000000..07718dc --- /dev/null +++ b/lib/app.js @@ -0,0 +1,36 @@ + +var http = require("http"), + url = require("url"), + path = require("path"), + fs = require("fs"), + req = require("./wsrequest.js"), + localPort = 8888, + defaultLayout = "standard", + defaultMain = null; + + + + + +exports.setPort = function(port) { + localPort = port; +} + +exports.start = function() { + // initialise req + req.setDefaultLayout(defaultLayout); + req.setDefaultMain(defaultMain); + + + http.createServer(req.wsRequest).listen(localPort); + + console.log("Server running on port: ", localPort); +} + +exports.setDefaultLayout = function(layout) { + defaultLayout = layout; +} + +exports.setDefaultMain = function(main) { + defaultMain = main; +} \ No newline at end of file diff --git a/lib/layouts.js b/lib/layouts.js new file mode 100644 index 0000000..a6c0a81 --- /dev/null +++ b/lib/layouts.js @@ -0,0 +1,18 @@ +exports.standard = function () { + var lay = ""; + lay += ""; + lay += ""; + lay += "
"; + + return lay; +} + + +exports.straight = function () { + var lay = ""; + lay += ""; + lay += ""; + lay += "
"; + + return lay; +} \ No newline at end of file diff --git a/lib/wsrequest.js b/lib/wsrequest.js index 021725b..a7ad086 100644 --- a/lib/wsrequest.js +++ b/lib/wsrequest.js @@ -4,13 +4,13 @@ var fs = require("fs"); var myparse = require("./myparse.js"); var webmain = require("./webmain.js"); -var staticExtensions = ["html", "gif", "jpg", "css", "js", "ico"]; +//var staticExtensions = ["html", "gif", "jpg", "css", "js", "ico"]; function wsRequest(request, response) { var isStatic = 0; var purl = url.parse(request.url); - staticExtensions.forEach(function testExtn(setest) { + /*staticExtensions.forEach(function testExtn(setest) { console.log("testing url: ", request.url); console.log("against: ", purl.pathname); var chk = purl.pathname.split("."); @@ -20,12 +20,23 @@ function wsRequest(request, response) { if(chkid != -1) { isStatic = 1; } - }); + });*/ + + // if the end of the pathname is something.something, we assume static + var lpath = purl.pathname.split("/").pop(); + var idx = lpath.indexOf("."); + console.log("testing url: ", request.url); + console.log("against: ", purl.pathname); + console.log("lpath is: '%s'", lpath); + console.log("type is: '%s'", typeof lpath); + console.log("idx is: ", idx); + + if(idx > 0) isStatic = 1; if(isStatic == 1) { // do the static - var servethis = purl.pathname.split("/").pop(); - serveStatic(servethis, response); + console.log("Service as static"); + serveStatic(lpath, response); return; } -- 1.7.0.4