elysia icon indicating copy to clipboard operation
elysia copied to clipboard

URL param match by regex

Open vidz1979 opened this issue 1 year ago • 2 comments

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)

vidz1979 avatar Jan 24 '24 21:01 vidz1979

I need this feature, too

yassine-zhang avatar Jul 28 '24 13:07 yassine-zhang

Match routes with regex is a really evil action. It very slow and may cause ReDoS attack

kravetsone avatar Jul 28 '24 16:07 kravetsone

Close as not going to implement as mentioned by kravetsone and overhead

SaltyAom avatar Aug 30 '24 18:08 SaltyAom