master
Dave Winer 9 years ago
parent ffba20e201
commit 88c852cff0

@ -88,6 +88,10 @@ There will always be more work to do here. ;-)
#### Updates
##### v0.67 7/30/15 by DW
New redirect feature for individual pages. In config.json, create a struct called redirects. The name of each element is the path to a file in the folder, and the value of each is the URL we will redirect to. On each request for that domain, we look in the redirects table to see if the request should be redirected. Here's an <a href="https://gist.github.com/scripting/8295f373c61dd9f5ce97">example</a> of the config.json for smallpicture.com. It redirects from an <a href="http://smallpicture.com/outlinerHowto.html">old version</a> of the outliner howto to the newer version.
##### v0.66 7/19/15 by DW
In prefs.json a new value, legalPathChars, defaults to the empty string. In this string you can specify characters that are legal in paths on your server. We are very conservative in what we will allow in paths, but if you need to use one of the characters that we consider illegal, add it to this string.

@ -1,4 +1,4 @@
var myVersion = "0.66a", myProductName = "PagePark";
var myVersion = "0.67c", myProductName = "PagePark";
/* The MIT License (MIT)
Copyright (c) 2014-2015 Dave Winer
@ -254,6 +254,11 @@ function handleHttpRequest (httpRequest, httpResponse) {
httpResponse.end (htmtext);
});
}
function returnRedirect (urlRedirectTo, flPermanent) { //7/30/15 by DW
var code = (flPermanent) ? 301 : 302;
httpResponse.writeHead (code, {"Location": urlRedirectTo, "Content-Type": "text/plain"});
httpResponse.end ("Redirect to " + urlRedirectTo + ".");
}
function findSpecificFile (folder, specificFname, callback) {
specificFname = specificFname.toLowerCase (); //7/16/15 by DW
fs.readdir (folder, function (err, list) {
@ -347,6 +352,19 @@ function handleHttpRequest (httpRequest, httpResponse) {
}
});
}
function serveRedirect (lowerpath, config) { //7/30/15 by DW -- return true if we handled the request
if (config.redirects !== undefined) {
for (x in config.redirects) {
if (x.toLowerCase () == lowerpath) {
var urlRedirectTo = config.redirects [x];
console.log ("serveRedirect: urlRedirectTo == " + urlRedirectTo);
returnRedirect (urlRedirectTo);
return (true);
}
}
}
return (false);
}
function delegateRequest (urlToDelegateTo) {
var theRequest = {
url: urlToDelegateTo,
@ -442,10 +460,8 @@ function handleHttpRequest (httpRequest, httpResponse) {
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 + ".");
}
@ -506,16 +522,18 @@ function handleHttpRequest (httpRequest, httpResponse) {
}
}
else {
if (stats.isDirectory ()) {
if (!utils.endsWith (f, "/")) {
f += "/";
if (!serveRedirect (lowerpath, config)) { //7/30/15 by DW -- it wasn't a redirect
if (stats.isDirectory ()) {
if (!utils.endsWith (f, "/")) {
f += "/";
}
findSpecificFile (f, pageparkPrefs.indexFilename, function (findex) {
serveFile (findex, config);
});
}
else {
serveFile (f, config);
}
findSpecificFile (f, pageparkPrefs.indexFilename, function (findex) {
serveFile (findex, config);
});
}
else {
serveFile (f, config);
}
}
});

Loading…
Cancel
Save