Skip to content

Commit

Permalink
Flip order of retrieval for doc pages
Browse files Browse the repository at this point in the history
* In case someone requests a page that doesn't exist don't bother reading the file list

Post fix for OpenUserJS#202
  • Loading branch information
Martii committed Nov 5, 2015
1 parent b2d515e commit 7f9011d
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions controllers/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,33 +70,6 @@ exports.view = function (aReq, aRes, aNext) {

//--- Tasks

// Read file listing
tasks.push(
function (aCallback) {
fs.readdir(documentPath, function (aErr, aFileList) {
var file = null;

if (aErr || !aFileList) {
aCallback({ statusCode: 500, statusMessage : 'Error retrieving page list' });
return;
}

// Dynamically create a file listing of the pages
options.fileList = [];
for (file in aFileList) {
if (/\.md$/.test(aFileList[file])) {
options.fileList.push({
href: aFileList[file].replace(/\.md$/, ''),
textContent: aFileList[file].replace(/\.md$/, '').replace(/-/g, ' ')
});
}
}

aCallback(null);
});
}
);

// Read the requested md file contents
tasks.push(
function (aCallback) {
Expand Down Expand Up @@ -131,6 +104,33 @@ exports.view = function (aReq, aRes, aNext) {
});
}
);

// Read file listing
tasks.push(
function (aCallback) {
fs.readdir(documentPath, function (aErr, aFileList) {
var file = null;

if (aErr || !aFileList) {
aCallback({ statusCode: 500, statusMessage : 'Error retrieving page list' });
return;
}

// Dynamically create a file listing of the pages
options.fileList = [];
for (file in aFileList) {
if (/\.md$/.test(aFileList[file])) {
options.fileList.push({
href: aFileList[file].replace(/\.md$/, ''),
textContent: aFileList[file].replace(/\.md$/, '').replace(/-/g, ' ')
});
}
}

aCallback(null);
});
}
);
}
else {
// Page metadata
Expand Down

0 comments on commit 7f9011d

Please sign in to comment.