简体   繁体   中英

How to match flexible url using koa-router in Node.js?

For example,

router.get('/files/...', ->) I want to match /files/a , /files/a/b , /files/a/b/c and so on.

Then, a , a/b , a/b/c will be my handle file path.

This should work for the path, using a regex instead of a string: /\\/files\\/(.*)/ -- then the path info should be in this.params[0] .

Side note -- if you're using this to serve files directly from the server, make sure to check for a directory traversal attack (often looks like using .. in the requested path multiple times) so that you don't inadvertently expose other files on the system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM