[英]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. router.get('/files/...', ->)
我想匹配/files/a
, /files/a/b
, /files/a/b/c
等。
Then, a
, a/b
, a/b/c
will be my handle file path. 然后,
a
, a/b
, a/b/c
将是我的句柄文件路径。
This should work for the path, using a regex instead of a string: /\\/files\\/(.*)/
-- then the path info should be in this.params[0]
. 这应该适用于路径,使用正则表达式而不是字符串:/
/\\/files\\/(.*)/
-然后路径信息应位于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. 旁注-如果使用此方法直接从服务器提供文件,请确保检查目录遍历攻击(通常看起来像在请求的路径中多次使用
..
),以免您无意间暴露其他攻击文件在系统上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.