new request layout bits
authorpaulr <paulr@tv.pjr.cc>
Sun, 23 Dec 2012 12:19:30 +0000 (23:19 +1100)
committerpaulr <paulr@tv.pjr.cc>
Sun, 23 Dec 2012 12:19:30 +0000 (23:19 +1100)
app.js [deleted file]
lib/app.js [new file with mode: 0644]
lib/layouts.js [new file with mode: 0644]
lib/wsrequest.js

diff --git a/app.js b/app.js
deleted file mode 100644 (file)
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 (file)
index 0000000..07718dc
--- /dev/null
@@ -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 (file)
index 0000000..a6c0a81
--- /dev/null
@@ -0,0 +1,18 @@
+exports.standard = function () {
+       var lay = "<html><head><?njs header ?></head><body><?nfs title ?>";
+       lay += "<table width=\"100%\"><tr><td><?njs menu ?></td></tr>";
+       lay += "<tr valign=\"top\"><td></td><?njs sidebar ?><td><?njs body ?></td></tr>";
+       lay += "<tr><td><?njs footer ?></td></tr></table>";
+       
+       return lay;
+}
+
+
+exports.straight = function () {
+       var lay = "<html><head><?njs header ?></head><body><?nfs title ?>";
+       lay += "<table width=\"100%\"><tr><td><?njs menu ?></td></tr>";
+       lay += "<tr valign=\"top\"><td></td><?njs sidebar ?><td><?njs body ?></td></tr>";
+       lay += "<tr><td><?njs footer ?></td></tr></table>";
+       
+       return lay;
+}
\ No newline at end of file
index 021725b..a7ad086 100644 (file)
@@ -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;
        }