hostr
Version:
A simple web server for the current working directory. Used for hello world style web sites hosting only files in current directory structure. Watches files and integrates with LiveReload.
44 lines (35 loc) • 840 B
JavaScript
;
import Debug from './debug.js';
const debug = Debug(process.env.QUIET === 'true');
/**
* Router
*
* @param {String} path A RegEx or String to match router to
* @param {Object} handler A callback, function(req, res, next)
* @return {Router} A instance of Router
*/
export default (path, handler) => {
/**
* Instance
*/
return {
/**
* Check if the route matches
*
* @return {Boolean} True if the URL matches and false otherwise
*/
match(req) {
if(!req || !req.url) return false;
if(typeof path === 'string') {
return req.url.match(path) && req.url.match(path).index === 0;
// RegExp
} else {
return req.url.match(path) !== null;
}
},
/**
* Handle this route execution
*/
handle: handler
};
};