Skip to content

Commit

Permalink
feat: add a getDefaultDocument method that returns the default docume…
Browse files Browse the repository at this point in the history
…nt for a given directory if fou
  • Loading branch information
teclone committed Jul 21, 2018
1 parent d2c13b3 commit 3d2203c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/modules/StaticFileServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* static file server module
*/
import path from 'path';
import fs from 'fs';
import crypto from 'crypto';

export default class {
Expand Down Expand Up @@ -72,4 +73,17 @@ export default class {

return hash.digest('hex').substring(0, length || 16);
}

/**
* returns the directories default document if any
*@param {string} dir - dir or file path.
*@returns {string}
*/
getDefaultDocument(dir) {
for(let file of this.defaultDocuments)
if (fs.existsSync(path.join(dir, '/', file)))
return file;

return '';
}
}

0 comments on commit 3d2203c

Please sign in to comment.