diff --git a/README.md b/README.md
index e17c39d..3e73261 100644
--- a/README.md
+++ b/README.md
@@ -88,15 +88,19 @@ There will always be more work to do here. ;-)
#### Updates
-##### v0.63 6/27/15 by DW
+##### v0.64 7/7/15 by DW
-If you add ?format=json to a request for an OPML file, you'll get a JSON representation of the outline. This is useful for single-page JavaScript apps that want to use the outlineBrowser toolkit to diplay the contents. An example of this is davewiner.com.
+I wanted to do a site redirect that was more than just a domain name change.
-To do this I needed to write a JS page that's served by PagePark that returns the JSON representation of a specific OPML file. Here's a gist containing the code. And a call to that page. It's extra-nice that this feature could be added without modifying PagePark. It's starting to become a real platform! :-)
+If a request came in for: http://archive.scripting.com/2007/12.
-In both cases, the CORS header allows access from anywhere.
+I wanted it to redirect to: http://scripting.com/2007/12.html
-And in both cases include nodes are resolved.
+That was accomplished with a new element in config.json: jsSiteRedirect. Its value is a JavaScript expression. You can access the path in the variable parsedUrl.pathname.
+
+This is what config.json in the folder archive.scripting.com looks like.
+
+{"jsSiteRedirect": "'http://scripting.com' + parsedUrl.pathname + '.html'"}
##### v0.62 6/25/15 by DW
diff --git a/pagepark.js b/pagepark.js
index 28ff4f6..35ce5dd 100644
--- a/pagepark.js
+++ b/pagepark.js
@@ -1,4 +1,4 @@
-var myVersion = "0.64a", myProductName = "PagePark";
+var myVersion = "0.63a", myProductName = "PagePark";
//The MIT License (MIT)
@@ -310,30 +310,21 @@ function handleHttpRequest (httpRequest, httpResponse) {
}
break;
case config.extOpmlFiles: //6/23/15 by DW
- var opmltext = data.toString ();
- if (formatParam == "json") {
- opmlLib.readOpmlString (opmltext, function (theOutline) {
- httpResponse.writeHead (200, {"Content-Type": "application/json", "Access-Control-Allow-Origin": "*"});
- httpResponse.end (utils.jsonStringify (theOutline));
+ var flReturnHtml = (!hasAcceptHeader ("text/x-opml")) && (formatParam != "opml");
+ if (pageparkPrefs.flProcessOpmlFiles && config.flProcessOpmlFiles && flReturnHtml) { //6/24/15 by DW
+ getOpmlTemplate (function (theTemplate) {
+ var opmltext = data.toString (), pagetable = new Object ();
+ opmlLib.readOpmlString (opmltext, function (theOutline) {
+ pagetable.bodytext = utils.jsonStringify (theOutline);
+ pagetable.title = utils.stringLastField (f, "/");
+ var s = utils.multipleReplaceAll (theTemplate, pagetable, false, "[%", "%]");
+ httpResponse.writeHead (200, {"Content-Type": "text/html"});
+ httpResponse.end (s);
+ });
});
}
else {
- var flReturnHtml = (!hasAcceptHeader ("text/x-opml")) && (formatParam != "opml");
- if (pageparkPrefs.flProcessOpmlFiles && config.flProcessOpmlFiles && flReturnHtml) { //6/24/15 by DW
- getOpmlTemplate (function (theTemplate) {
- var pagetable = new Object ();
- opmlLib.readOpmlString (opmltext, function (theOutline) {
- pagetable.bodytext = utils.jsonStringify (theOutline);
- pagetable.title = utils.stringLastField (f, "/");
- var s = utils.multipleReplaceAll (theTemplate, pagetable, false, "[%", "%]");
- httpResponse.writeHead (200, {"Content-Type": "text/html"});
- httpResponse.end (s);
- });
- });
- }
- else {
- defaultReturn ("text/xml", data);
- }
+ defaultReturn ("text/xml", data);
}
break;
default:
@@ -437,6 +428,20 @@ function handleHttpRequest (httpRequest, httpResponse) {
fsSureFilePath (domainsPath, function () { //make sure domains folder exists
getConfigFile (actualhost, function (config) { //get config.json, if it exists -- 1/18/15 by DW
if (config != undefined) {
+ if (config.jsSiteRedirect != undefined) { //7/7/15 by DW
+ console.log ("config.jsSiteRedirect == " + config.jsSiteRedirect);
+ try {
+ var urlRedirect = eval (config.jsSiteRedirect.toString ());
+ console.log ("urlRedirect == " + urlRedirect);
+ httpResponse.writeHead (302, {"Location": urlRedirect.toString (), "Content-Type": "text/plain"});
+ httpResponse.end ("Temporary redirect to " + urlRedirect + ".");
+ }
+ catch (err) {
+ httpResponse.writeHead (500, {"Content-Type": "text/plain"});
+ httpResponse.end ("Error running " + config.jsSiteRedirect + ": \"" + err.message + "\"");
+ }
+ return;
+ }
if (config.urlSiteRedirect != undefined) {
var urlRedirect = config.urlSiteRedirect + parsedUrl.pathname;
httpResponse.writeHead (302, {"Location": urlRedirect, "Content-Type": "text/plain"});