From a5497b5bbc722543d5052c6ad74661a5ae38cc56 Mon Sep 17 00:00:00 2001 From: Paul J R Date: Sun, 23 Dec 2012 06:10:44 +1100 Subject: [PATCH] rearranging project layout --- lib/purls/main.js | 31 ------------------------------- lib/purls/main_footer.js | 7 ------- lib/purls/main_head.js | 8 -------- lib/purls/main_menu.js | 8 -------- lib/purls/web_body.js | 8 -------- lib/purls/web_nobody.js | 8 -------- lib/purls/web_test.js | 11 ----------- lib/webmain.js | 31 +++++++++++++++++++++++++++++++ lib/wsrequest.js | 6 +++--- purls/main_footer.js | 7 +++++++ purls/main_head.js | 8 ++++++++ purls/main_menu.js | 8 ++++++++ purls/web_body.js | 8 ++++++++ purls/web_nobody.js | 8 ++++++++ purls/web_test.js | 11 +++++++++++ 15 files changed, 84 insertions(+), 84 deletions(-) delete mode 100644 lib/purls/main.js delete mode 100644 lib/purls/main_footer.js delete mode 100644 lib/purls/main_head.js delete mode 100644 lib/purls/main_menu.js delete mode 100644 lib/purls/web_body.js delete mode 100644 lib/purls/web_isbase.js delete mode 100644 lib/purls/web_nobody.js delete mode 100644 lib/purls/web_test.js create mode 100644 lib/webmain.js create mode 100644 purls/main_footer.js create mode 100644 purls/main_head.js create mode 100644 purls/main_menu.js create mode 100644 purls/web_body.js create mode 100644 purls/web_isbase.js create mode 100644 purls/web_nobody.js create mode 100644 purls/web_test.js diff --git a/lib/purls/main.js b/lib/purls/main.js deleted file mode 100644 index c5bf240..0000000 --- a/lib/purls/main.js +++ /dev/null @@ -1,31 +0,0 @@ -function serveMain(request, response, callback) { - response.writeHead(200); - - serveBody(request, response, function(request, response, callback) { - response.write("server main body"); - callback(request, response); - }); - return; -} - -function serveBody(request, response, bodyFunction) { - response.writeHead(200); - require("./main_head.js").go(request, response, function(request, response) { - response.write(""); - response.end(); - }); - }); - }); - }); - return; -} - - -exports.serveMain = serveMain; -exports.serveBody = serveBody; diff --git a/lib/purls/main_footer.js b/lib/purls/main_footer.js deleted file mode 100644 index 19f275e..0000000 --- a/lib/purls/main_footer.js +++ /dev/null @@ -1,7 +0,0 @@ -function go(request, response, callback) { - response.write("

Copyright PJR.cc 2012"); - callback(request, response); - return; -} - -exports.go = go; \ No newline at end of file diff --git a/lib/purls/main_head.js b/lib/purls/main_head.js deleted file mode 100644 index 463d8dd..0000000 --- a/lib/purls/main_head.js +++ /dev/null @@ -1,8 +0,0 @@ -function go(request, response, callback) { - console.log("in main_head.go"); - response.write("im a head"); - callback(request, response); - return; -} - -exports.go = go; \ No newline at end of file diff --git a/lib/purls/main_menu.js b/lib/purls/main_menu.js deleted file mode 100644 index 042b8a8..0000000 --- a/lib/purls/main_menu.js +++ /dev/null @@ -1,8 +0,0 @@ -function go(request, response, callback) { - console.log("in main_head.go"); - response.write("

Title

"); - require("./main_menu.js").go(request, response, function(request, response) { - response.write("
"); - bodyFunction(request, response, function(request, response) { - response.write("
"); - require("./main_footer.js").go(request, response, function(request, response) { - response.write("
menuitem1item2item3
"); - callback(request, response); - return; -} - -exports.go = go; \ No newline at end of file diff --git a/lib/purls/web_body.js b/lib/purls/web_body.js deleted file mode 100644 index c9671ed..0000000 --- a/lib/purls/web_body.js +++ /dev/null @@ -1,8 +0,0 @@ -function process(request, response, callback) { - response.write("Body"); - callback(request, response); -} - - -exports.process = process; -exports.requireBody = function() { return true;}; diff --git a/lib/purls/web_isbase.js b/lib/purls/web_isbase.js deleted file mode 100644 index e69de29..0000000 diff --git a/lib/purls/web_nobody.js b/lib/purls/web_nobody.js deleted file mode 100644 index 67eef07..0000000 --- a/lib/purls/web_nobody.js +++ /dev/null @@ -1,8 +0,0 @@ -function process(request, response, callback) { - response.writeHead(302, { 'Location':'/body/'}) - callback(request, response); -} - - -exports.process = process; -exports.requireBody = function() { return false;}; diff --git a/lib/purls/web_test.js b/lib/purls/web_test.js deleted file mode 100644 index e746be5..0000000 --- a/lib/purls/web_test.js +++ /dev/null @@ -1,11 +0,0 @@ -function requireBody() { - return true; -} - -function process(request, response, callback) { - response.write("from callback
"); - callback(request, response); -} - -exports.requireBody = requireBody; -exports.process = process; diff --git a/lib/webmain.js b/lib/webmain.js new file mode 100644 index 0000000..c5bf240 --- /dev/null +++ b/lib/webmain.js @@ -0,0 +1,31 @@ +function serveMain(request, response, callback) { + response.writeHead(200); + + serveBody(request, response, function(request, response, callback) { + response.write("server main body"); + callback(request, response); + }); + return; +} + +function serveBody(request, response, bodyFunction) { + response.writeHead(200); + require("./main_head.js").go(request, response, function(request, response) { + response.write(""); + response.end(); + }); + }); + }); + }); + return; +} + + +exports.serveMain = serveMain; +exports.serveBody = serveBody; diff --git a/lib/wsrequest.js b/lib/wsrequest.js index c7797fc..021725b 100644 --- a/lib/wsrequest.js +++ b/lib/wsrequest.js @@ -2,7 +2,7 @@ var url = require("url"); var path = require("path"); var fs = require("fs"); var myparse = require("./myparse.js"); -var webmain = require("./purls/main.js"); +var webmain = require("./webmain.js"); var staticExtensions = ["html", "gif", "jpg", "css", "js", "ico"]; @@ -43,7 +43,7 @@ function wsRequest(request, response) { } var thispurl = purl.pathname.split("/")[1]; - fs.stat("./lib/purls/web_"+thispurl+".js", function (err, stats) { + fs.stat("./purls/web_"+thispurl+".js", function (err, stats) { console.log("get purl is "+thispurl+" and err "+err+" and "+stats); if(err) { response.writeHead(404, {"Content-Type": "text/plain"}); @@ -51,7 +51,7 @@ function wsRequest(request, response) { response.end(); return; } - var thiserv = require("./purls/web_"+thispurl+".js"); + var thiserv = require("../purls/web_"+thispurl+".js"); if(thiserv.requireBody()) { console.log("yubber is true"); webmain.serveBody(request, response, thiserv.process); diff --git a/purls/main_footer.js b/purls/main_footer.js new file mode 100644 index 0000000..19f275e --- /dev/null +++ b/purls/main_footer.js @@ -0,0 +1,7 @@ +function go(request, response, callback) { + response.write("

Copyright PJR.cc 2012"); + callback(request, response); + return; +} + +exports.go = go; \ No newline at end of file diff --git a/purls/main_head.js b/purls/main_head.js new file mode 100644 index 0000000..463d8dd --- /dev/null +++ b/purls/main_head.js @@ -0,0 +1,8 @@ +function go(request, response, callback) { + console.log("in main_head.go"); + response.write("im a head"); + callback(request, response); + return; +} + +exports.go = go; \ No newline at end of file diff --git a/purls/main_menu.js b/purls/main_menu.js new file mode 100644 index 0000000..042b8a8 --- /dev/null +++ b/purls/main_menu.js @@ -0,0 +1,8 @@ +function go(request, response, callback) { + console.log("in main_head.go"); + response.write("

Title

"); + require("./main_menu.js").go(request, response, function(request, response) { + response.write("
"); + bodyFunction(request, response, function(request, response) { + response.write("
"); + require("./main_footer.js").go(request, response, function(request, response) { + response.write("
menuitem1item2item3
"); + callback(request, response); + return; +} + +exports.go = go; \ No newline at end of file diff --git a/purls/web_body.js b/purls/web_body.js new file mode 100644 index 0000000..c9671ed --- /dev/null +++ b/purls/web_body.js @@ -0,0 +1,8 @@ +function process(request, response, callback) { + response.write("Body"); + callback(request, response); +} + + +exports.process = process; +exports.requireBody = function() { return true;}; diff --git a/purls/web_isbase.js b/purls/web_isbase.js new file mode 100644 index 0000000..e69de29 diff --git a/purls/web_nobody.js b/purls/web_nobody.js new file mode 100644 index 0000000..67eef07 --- /dev/null +++ b/purls/web_nobody.js @@ -0,0 +1,8 @@ +function process(request, response, callback) { + response.writeHead(302, { 'Location':'/body/'}) + callback(request, response); +} + + +exports.process = process; +exports.requireBody = function() { return false;}; diff --git a/purls/web_test.js b/purls/web_test.js new file mode 100644 index 0000000..e746be5 --- /dev/null +++ b/purls/web_test.js @@ -0,0 +1,11 @@ +function requireBody() { + return true; +} + +function process(request, response, callback) { + response.write("from callback
"); + callback(request, response); +} + +exports.requireBody = requireBody; +exports.process = process; -- 1.7.0.4