Improved path matching for ambiorix with path-to-regexp
🚥 Lengthy Explanation
Internally ambiorix must match paths with patterns.
That is, if the user wants to handle app$get("/:path")
(see parameters) then regular expressions must be used.
The current implementation works for probably 99% of cases
but in rare places you may encounter some issues.
The trick implemented is simply that of lex, take the
longer match.
This is because the job of converting paths to patterns is complicated. The Django framework does not do that for instance and require the user to enter a valid regular expression as path. Express.js uses path-to-regexp which is very robust but also complex; it's a lexer, parser, and compiler.
Therefore it may take some time before ambiorix sees such a robust implementation: {slighe} is here to fill the gap in the meantime. It's not part of the main package since it requires an installation of the V8 engine.
You can install the development version of slighe like so:
# install.packages("remotes")
remotes::install_github("devOpifex/slighe")
Simply pass it to the use
method.
library(slighe)
library(ambiorix)
app <- Ambiorix$new()
# use slighe
app$use(slighe())
app$get("/", \(req, res) {
res$send("Hello")
})
app$get("/:hash", \(req, res) {
res$send("world")
})
app$start()