aws-lambda-router
aws-lambda-router copied to clipboard
How can I create path vars that aren't separated with "/"
I have a route that looks something like this:
path: "thing/{var1}/{var2}/{var3}/{name}.{extension}"
But right now the code that extract path names and path values doesn't support this.
Now my regex foo is super lame. I was hoping someone could help me identify the fix for this. If it's something this lib doesnt want to support I can fork.
if it is, I dont mind submitted a PR with some guidance.
const extractPathValues = (pathExpression: string, httpPath: string) => {
const pathExpressionPattern = pathExpression.replace(/{[\w]+}|:[\w]+/g, '([^/]+)')
const pathValueRegex = new RegExp(`^${pathExpressionPattern}$`)
const pathValues = pathValueRegex.exec(httpPath)
return pathValues && pathValues.length > 0 ? pathValues.slice(1) : null
}
const extractPathNames = (pathExpression: string) => {
const pathExpressionPattern = pathExpression.replace(/{[\w.]+}|:[\w.]+/g, '[:{]([\\w]+)}?')
const pathNameRegex = new RegExp(`^${pathExpressionPattern}$`)
const pathNames = pathNameRegex.exec(pathExpression)
return pathNames && pathNames.length > 0 ? pathNames.slice(1) : null
}