--- /dev/null
+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
--- /dev/null
+var path = require("fs");
+
+function useBody() {
+ return;
+}
+
+function parse(base, purl, response, servicer) {
+ var pathCheck = "./lib/web_"+base+".js";
+ console.log("path check on ", pathCheck);
+ fs.exists(pathCheck, function (exists) {
+ if(!exists) console.log("not exists: ", base);
+ else {
+ servicer(purl, response, parse);
+ console.log("base exists: ", base);
+ }
+ });
+}
+
+exports.useBody = useBody;
+exports.parse = parse;
+exports.process = process;
--- /dev/null
+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("<table border=\"1\" width=\"100%\"><tr><td><h1>Title</h1></td></tr><tr><td>");
+ require("./main_menu.js").go(request, response, function(request, response) {
+ response.write("</td></tr><tr><td>");
+ bodyFunction(request, response, function(request, response) {
+ response.write("</td></tr><tr><td>");
+ require("./main_footer.js").go(request, response, function(request, response) {
+ response.write("</td></tr></body></html>");
+ response.end();
+ });
+ });
+ });
+ });
+ return;
+}
+
+
+exports.serveMain = serveMain;
+exports.serveBody = serveBody;
--- /dev/null
+function go(request, response, callback) {
+ response.write("<br><br><font size=\"-1\"><i>Copyright PJR.cc 2012</i></font>");
+ callback(request, response);
+ return;
+}
+
+exports.go = go;
\ No newline at end of file
--- /dev/null
+function go(request, response, callback) {
+ console.log("in main_head.go");
+ response.write("<html><head><title>im a head</title></head><body>");
+ callback(request, response);
+ return;
+}
+
+exports.go = go;
\ No newline at end of file
--- /dev/null
+function go(request, response, callback) {
+ console.log("in main_head.go");
+ response.write("<table><tr><th>menu</th><td>item1</td><td>item2</td><td>item3</td></tr></table>");
+ callback(request, response);
+ return;
+}
+
+exports.go = go;
\ No newline at end of file
--- /dev/null
+var url = require("url");
+var path = require("path");
+var fs = require("fs");
+var myparse = require("./myparse.js");
+var webmain = require("./purls/main.js");
+
+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) {
+ console.log("testing url: ", request.url);
+ console.log("against: ", purl.pathname);
+ var chk = purl.pathname.split(".");
+ console.log("chk: ", chk);
+ var chkid = staticExtensions.indexOf(chk[chk.length-1].toLowerCase());
+ console.log("chkid is ", chkid);
+ if(chkid != -1) {
+ isStatic = 1;
+ }
+ });
+
+ if(isStatic == 1) {
+ // do the static
+ var servethis = purl.pathname.split("/").pop();
+ serveStatic(servethis, response);
+ return;
+ }
+
+ //console.log("request: ", request);
+ console.log("purl: ", purl);
+
+ // now we need to find the extension used
+ // to serve the request based no the first purl
+ if(purl.pathname == "/") {
+ console.log("Serv main");
+ webmain.serveMain(request, response, function (request, response) {
+ response.end();
+ });
+ return;
+ }
+
+ var thispurl = purl.pathname.split("/")[1];
+ fs.stat("./lib/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"});
+ response.write("404 Not Found\n");
+ response.end();
+ return;
+ }
+ var thiserv = require("./purls/web_"+thispurl+".js");
+ if(thiserv.requireBody()) {
+ console.log("yubber is true");
+ webmain.serveBody(request, response, thiserv.process);
+ } else {
+ console.log("yubber is false");
+ thiserv.process(request, response, function(request, response) {
+ response.end();
+ });
+ }
+ return;
+ });
+
+
+ return;
+}
+
+function serveStatic(staticname, response) {
+ var pathName = "./res/"+staticname;
+ console.log("Pathname for check is ", pathName);
+ fs.exists(pathName, function(exists) {
+ if(!exists) {
+ response.writeHead(404, {"Content-Type": "text/plain"});
+ response.write("404 Not Found\n");
+ response.end();
+ return;
+ }
+
+ fs.readFile(pathName, "binary", function(err, file) {
+ if(err) {
+ response.writeHead(500, {"Content-Type": "text/plain"});
+ response.write(err + "\n");
+ response.end();
+ return;
+ }
+
+ response.writeHead(200);
+ response.write(file, "binary");
+ response.end();
+ });
+ });
+}
+
+exports.wsRequest = wsRequest;
--- /dev/null
+
+<br><br>
+<font size="-1">Copyright PJR.cc 2012</font>
+</body>
+</html>
--- /dev/null
+<html>
+<head>
+<title>Title!</title>
+</head>
+<body>
--- /dev/null
+<h1>this is a test</h1>
+
+this is a journey, into sound...