src/middleware/simpleRouter.js
function compareRouteAndApplyArgs (route, request_url, request_method) {
	if (route.method !== request_method) {
		return false;
	}

	let template = route.path.split('/');
	if (template[0] === '') {
		template = template.slice(1); // Slice kills the emptystring before the leading slash
	}

	let actual = request_url.pathname.split('/');
	if (actual[0] === '') {
		actual = actual.slice(1); // Slice kills the emptystring before the leading slash
	}

	if (template.length != actual.length) {
		return false;
	}

	for (let i = 0; i < template.length; i++) {
		let actual_part = actual[i];
		let template_part = template[i];
		
		// Process variables first
		if (template_part[0] === '#') {
			// # templates only accept numbers
			if (isNaN(Number(actual_part))) {
				return false;
			}

			applyArg(request_url, template_part.substring(1), Number(actual_part));
			continue;
		}

		if (template_part[0] === '$') {
			// $ templates accept any non-slash alphanumeric character
			applyArg(request_url, template_part.substring(1), String(actual_part));
			// Continue so that 
			continue;
		}

		// Process exact matches second
		if (actual_part === template_part) {
			continue;
		}

		return false;
	}

	return true;
}
function compareRouteAndApplyArgs (route, request_url, request_method) {
	if (route.method !== request_method) {
		return false;
	}

	let template = route.path.split('/');
	if (template[0] === '') {
		template = template.slice(1); // Slice kills the emptystring before the leading slash
	}

	let actual = request_url.pathname.split('/');
	if (actual[0] === '') {
		actual = actual.slice(1); // Slice kills the emptystring before the leading slash
	}

	if (template.length != actual.length) {
		return false;
	}

	for (let i = 0; i < template.length; i++) {
		let actual_part = actual[i];
		let template_part = template[i];
		
		// Process variables first
		if (template_part[0] === '#') {
			// # templates only accept numbers
			if (isNaN(Number(actual_part))) {
				return false;
			}

			applyArg(request_url, template_part.substring(1), Number(actual_part));
			continue;
		}

		if (template_part[0] === '$') {
			// $ templates accept any non-slash alphanumeric character
			applyArg(request_url, template_part.substring(1), String(actual_part));
			// Continue so that 
			continue;
		}

		// Process exact matches second
		if (actual_part === template_part) {
			continue;
		}

		return false;
	}

	return true;
}
function compareRouteAndApplyArgs ( route , request_url , request_method ) { if ( route . method !== request_method ) { return false ; } let template = route . path . split ( '/' ) ; if ( template [ 0 ] === '' ) { template = template . slice ( 1 ) ; // Slice kills the emptystring before the leading slash } let actual = request_url . pathname . split ( '/' ) ; if ( actual [ 0 ] === '' ) { actual = actual . slice ( 1 ) ; // Slice kills the emptystring before the leading slash } if ( template . length != actual . length ) { return false ; } for ( let i = 0 ; i < template . length ; i ++ ) { let actual_part = actual [ i ] ; let template_part = template [ i ] ; // Process variables first if ( template_part [ 0 ] === '#' ) { // # templates only accept numbers if ( isNaN ( Number ( actual_part ) ) ) { return false ; } applyArg ( request_url , template_part . substring ( 1 ) , Number ( actual_part ) ) ; continue ; } if ( template_part [ 0 ] === '$' ) { // $ templates accept any non-slash alphanumeric character applyArg ( request_url , template_part . substring ( 1 ) , String ( actual_part ) ) ; // Continue so that  continue ; } // Process exact matches second if ( actual_part === template_part ) { continue ; } return false ; } return true ; }
Checks to see if the route matches the request, and if true assigns any applicable url variables and returns the route

@param {object} route - Route object from this simple router class
@param {object} route.method - HTTP method associated with this route
@param {object} route.path - HTTP path associated with this route
@param {object} request_url - Parsed HTTP request url
@param {string} request_method - HTTP request method
Checks to see if the route matches the request and if true assigns any applicable url variables and returns the route