[v5] Suggestion for migrating wildcard paths handling #5942
Closed
RecuencoJones
started this conversation in
General
Replies: 2 comments 3 replies
-
Ideally if you are using this for file access like in your example you would be more careful about it than just joining the string and reading from disk (ex. not exposing your file structure directly to the client). If you need a static file server, I suggest nginx not express, but if you really want to we have |
Beta Was this translation helpful? Give feedback.
2 replies
-
To achieve the old result, it should be enough to do |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
TL;DR: Simply use
Original post
Due to the updates on router and path-to-regex, handling wildcard routes requires a bit of work on the parameters to bring them back to the same values v4 produces when matching routes.
I found this code should work similarly and may help people migrate their routes if they expect variable file / folder paths:
I thought simply using
join()
would be enough, but when matching folders (e.g,/files/folder/
),req.params.param0
would be[ 'folder', '' ]
andjoin()
ignores the empty string value 😩Beta Was this translation helpful? Give feedback.
All reactions