added a method for setting resource path
authorpaulr <paulr@tv.pjr.cc>
Sun, 30 Dec 2012 10:43:13 +0000 (21:43 +1100)
committerpaulr <paulr@tv.pjr.cc>
Sun, 30 Dec 2012 10:43:13 +0000 (21:43 +1100)
examples/simple/myapp.js
examples/simple/purls/main_footer.js [deleted file]
examples/simple/purls/main_head.js [deleted file]
examples/simple/purls/main_menu.js [deleted file]
examples/simple/purls/web_body.js [deleted file]
examples/simple/purls/web_isbase.js [deleted file]
examples/simple/purls/web_nobody.js [deleted file]
examples/simple/purls/web_test.js [deleted file]
lib/app.js
lib/wsrequest.js

index 7eed9ea..dd24da3 100644 (file)
@@ -1,7 +1,17 @@
+// require the main njspurls modules
 var app = require("njspurls");
 
+// below we set a bunch of things globally for the app
+// set the port to listen to
 app.setPort(8888);
+
+// location for loading "purls"
 app.setPurlPath("./purls");
+
+// location for resources
+app.setResPath("./res");
+
+// purl to load for main page, i.e. /
 app.setDefaultMainPurl("main");
 app.addMenu("name1", "/linkto1");
 app.addMenu("name2", "/linkto2");
diff --git a/examples/simple/purls/main_footer.js b/examples/simple/purls/main_footer.js
deleted file mode 100644 (file)
index 19f275e..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-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
diff --git a/examples/simple/purls/main_head.js b/examples/simple/purls/main_head.js
deleted file mode 100644 (file)
index 463d8dd..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-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
diff --git a/examples/simple/purls/main_menu.js b/examples/simple/purls/main_menu.js
deleted file mode 100644 (file)
index 042b8a8..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-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
diff --git a/examples/simple/purls/web_body.js b/examples/simple/purls/web_body.js
deleted file mode 100644 (file)
index c9671ed..0000000
+++ /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/examples/simple/purls/web_isbase.js b/examples/simple/purls/web_isbase.js
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/examples/simple/purls/web_nobody.js b/examples/simple/purls/web_nobody.js
deleted file mode 100644 (file)
index 67eef07..0000000
+++ /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/examples/simple/purls/web_test.js b/examples/simple/purls/web_test.js
deleted file mode 100644 (file)
index e746be5..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-function requireBody() {
-       return true;
-}
-
-function process(request, response, callback) {
-       response.write("from callback<br>");
-       callback(request, response);
-}
-
-exports.requireBody = requireBody;
-exports.process = process;
index 4fc59b0..7879fbc 100644 (file)
@@ -26,6 +26,14 @@ exports.setPurlPath = function(setpath) {
        global.njspurls.mainPath = mainpath;
 }
 
+exports.setResPath = function(setpath) {
+       // default purl path is set based on the module.parent if its relative
+       var basename = path.dirname(module.parent.filename);
+       var mainpath = path.resolve(basename, setpath);
+       console.log("setting res path to ", mainpath);
+       global.njspurls.mainResPath = mainpath;
+}
+
 exports.setFooterText = function(text) {
        global.njspurls.footerText = text;
 }
index 20e71ba..6f7cb52 100644 (file)
@@ -236,7 +236,12 @@ function resolveAndCall(request, response, caller, purlClass, callback) {
 }
 
 function serveStatic(staticname, response) {
-       var pathName = "./res/"+staticname;
+       var pathName = "";
+       if(typeof global.njspurls.mainResPath != "undefined") {
+               pathName = global.njspurls.mainResPath + "/" + staticname;
+       } else {
+               pathName = "./res/"+staticname;
+       }
        console.log("Pathname for check is ", pathName);
        fs.exists(pathName, function(exists) {
                if(!exists) {