skeleton/modules/localServer.js
function FilesystemHandler(req, res, next, urlAlias, localPath, local = false) {
            const parsedUrl = url.parse(req.url);
            if (!parsedUrl.pathname.startsWith(urlAlias)) {
                return next();
            }

            const bareUrl = parsedUrl.pathname.substr(urlAlias.length);

            let filePath;
            if (localPath) {
                filePath = path.join(localPath, decodeURIComponent(bareUrl));
                if (filePath.toLowerCase().lastIndexOf(localPath.toLowerCase(), 0) !== 0) {
                    return respondWithCode(res, 400, 'Wrong path.');
                }
            } else {
                filePath = decodeURIComponent(bareUrl);
            }

            if (fs.existsSync(filePath)) {
                return local ?
                    createStreamProtocolResponse(filePath, res, () => {
                    }) :
                    send(req, encodeURIComponent(filePath)).pipe(res);
            }
            return local ? res.setStatusCode(404) : respondWithCode(res, 404, 'File does not exist.');
        }
function FilesystemHandler(req, res, next, urlAlias, localPath, local = false) {
            const parsedUrl = url.parse(req.url);
            if (!parsedUrl.pathname.startsWith(urlAlias)) {
                return next();
            }

            const bareUrl = parsedUrl.pathname.substr(urlAlias.length);

            let filePath;
            if (localPath) {
                filePath = path.join(localPath, decodeURIComponent(bareUrl));
                if (filePath.toLowerCase().lastIndexOf(localPath.toLowerCase(), 0) !== 0) {
                    return respondWithCode(res, 400, 'Wrong path.');
                }
            } else {
                filePath = decodeURIComponent(bareUrl);
            }

            if (fs.existsSync(filePath)) {
                return local ?
                    createStreamProtocolResponse(filePath, res, () => {
                    }) :
                    send(req, encodeURIComponent(filePath)).pipe(res);
            }
            return local ? res.setStatusCode(404) : respondWithCode(res, 404, 'File does not exist.');
        }
function FilesystemHandler ( req , res , next , urlAlias , localPath , local = false ) { const parsedUrl = url . parse ( req . url ) ; if ( ! parsedUrl . pathname . startsWith ( urlAlias ) ) { return next ( ) ; } const bareUrl = parsedUrl . pathname . substr ( urlAlias . length ) ; let filePath ; if ( localPath ) { filePath = path . join ( localPath , decodeURIComponent ( bareUrl ) ) ; if ( filePath . toLowerCase ( ) . lastIndexOf ( localPath . toLowerCase ( ) , 0 ) !== 0 ) { return respondWithCode ( res , 400 , 'Wrong path.' ) ; } } else { filePath = decodeURIComponent ( bareUrl ) ; } if ( fs . existsSync ( filePath ) ) { return local ? createStreamProtocolResponse ( filePath , res , ( ) => { } ) : send ( req , encodeURIComponent ( filePath ) ) . pipe ( res ) ; } return local ? res . setStatusCode ( 404 ) : respondWithCode ( res , 404 , 'File does not exist.' ) ; }
Provides files from the filesystem on a specified url alias.

@param {Object} req        - request object
@param {Object} res        - response object
@param {Function} next     - called on handler miss
@param {string} urlAlias   - url alias on which to serve the files
@param {string=} localPath - serve files only from this path
@param {boolean} local - local mode
Provides files from the filesystem on a specified url alias .