elysia
elysia copied to clipboard
URL param match by regex
What is the problem this feature would solve?
I am building a URL shortener and want to put my link id in the root of project. It is a nanoid with 7 characters. I am get errors because favicon.ico and all other non matched requests fall in the path.
server.get("/:id", async ({ params: { id }, set }) => {...})
What is the feature you are proposing to solve the problem?
Other frameworks offer the option to tell the param format using a regex. I think this can be useful here.
server.get("/:id{^[A-Za-z0-9_-]{7}$}", async ({ params: { id }, set }) => {...})
What alternatives have you considered?
Move my endpoint to a folder (/link/:id)
I need this feature, too
Match routes with regex is a really evil action. It very slow and may cause ReDoS attack
Close as not going to implement as mentioned by kravetsone and overhead