parent
42e8b36df4
commit
7611c1b2bf
@ -0,0 +1,25 @@
|
||||
deepmatch route, regex match route
|
||||
static assets
|
||||
middleware
|
||||
view engine
|
||||
user-defined services
|
||||
internationalization
|
||||
uploads & universal path
|
||||
CLI - view routes, template generation, start server, directives, output, args
|
||||
request level error handler
|
||||
develop/prod/debug modes
|
||||
logger scope (e.g. logger.verbose())
|
||||
favicon
|
||||
utility - root, path, is_windows, is_linux, is_mac
|
||||
authentication - user/session, oauth, jwt, &c.
|
||||
orm relations, subqueries, enum/bit fields, json handlers, scopes
|
||||
redis - redis client, redis rehydrated classes, redis sessions
|
||||
less/scss
|
||||
notifications - gotify/push/other mechanisms
|
||||
forms
|
||||
job queue - redis/db backed?
|
||||
comment all the things
|
||||
unit tests
|
||||
integration tests
|
||||
documentation & docs site
|
||||
events and observables?
|
@ -0,0 +1,43 @@
|
||||
import {Route, RouteParameters} from './Route.ts'
|
||||
|
||||
export class DeepmatchRoute extends Route {
|
||||
protected base_regex: RegExp
|
||||
|
||||
constructor(
|
||||
protected base: string
|
||||
) {
|
||||
super(base)
|
||||
this.base_regex = this.build_regex(this.split(base))
|
||||
}
|
||||
|
||||
public match(incoming: string): boolean {
|
||||
return this.base_regex.test(incoming.toLowerCase())
|
||||
}
|
||||
|
||||
public build_parameters(incoming: string): RouteParameters {
|
||||
const results = this.base_regex.exec(incoming.toLowerCase())
|
||||
if ( !results ) return {}
|
||||
|
||||
const [match, ...wildcards] = results
|
||||
const params: RouteParameters = {}
|
||||
let current_wildcard: number = 1
|
||||
|
||||
for ( const wild of wildcards ) {
|
||||
params[`$${current_wildcard}`] = wild
|
||||
current_wildcard += 1
|
||||
}
|
||||
|
||||
return params
|
||||
}
|
||||
|
||||
protected build_regex(base_parts: string[]) {
|
||||
const deepmatch_group = '([a-zA-Z0-9\\-\\_\\.\\/]+)' // allows for alphanum, -, _, ., and /
|
||||
const shallowmatch_group = '([a-zA-Z0-9\\-\\.\\_]+)' // allows for alphanum, -, ., and _
|
||||
|
||||
const regex = base_parts.map(part => {
|
||||
return part.split('**').join(deepmatch_group).split('*').join(shallowmatch_group)
|
||||
}).join('\\/')
|
||||
|
||||
return new RegExp(regex)
|
||||
}
|
||||
}
|
Loading…
Reference in new issue