Skip to content

Commit

Permalink
feat: Create the Static File Server module.
Browse files Browse the repository at this point in the history
This module serves out static files from the user defined public paths. It responds to the following
http method verbs made on any resource from the public paths: GET, HEAD, & OPTIONS. it has support
http cache-control headers and negotiates request before sending out a response. It does not serve
out sensitive files, files that starts with dot character. it supports byte range requests and sends
appropriate request content-type. It obeys http rules in this regards
  • Loading branch information
teclone committed Jul 21, 2018
1 parent 1b4cd8d commit 9ee7194
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/modules/StaticFileServer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* static file server module
*/
import path from 'path';

export default class {
/**
*@param {string} rootDir - the project root directory
*@param {Array} publicPaths - array of public paths to serve static files from
*@param {Object} mimeTypes - object of file mime types
*@param {Array} defaultDocuments - array of folder default documents
*@param {string} cacheControl - cache control header for static files
*/
constructor(rootDir, publicPaths, mimeTypes, defaultDocuments, cacheControl) {
this.publicPaths = publicPaths.map(publicPath => {
return path.join(rootDir, publicPath, '/');
});
this.mimeTypes = mimeTypes;
this.defaultDocuments = defaultDocuments;
this.cacheControl = cacheControl || 'no-cache, max-age=86400';
}

/**
* return instance identity
*/
get [Symbol.toStringTag]() {
return 'StaticFileServer';
}
}

0 comments on commit 9ee7194

Please sign in to comment.