Closed minchao closed 5 years ago
參考 Express Routing 文件,將路徑匹配的 regex 改為簡單的 string pattern。
Route paths, in combination with a request method, define the endpoints at which requests can be made. Route paths can be strings, string patterns, or regular expressions. Express uses path-to-regexp for matching the route paths
Route paths, in combination with a request method, define the endpoints at which requests can be made. Route paths can be strings, string patterns, or regular expressions.
Express uses path-to-regexp for matching the route paths
範例:
原本匹配的路徑 '^/$',經過 path-to-regexp 後會變成 /^\^\/\$(?:\/)?$/i,修改為 /,轉換後則是 /^\/(?:\/)?$/i。
'^/$'
/^\^\/\$(?:\/)?$/i
/
/^\/(?:\/)?$/i
如果要直接使用 regex,可改寫為
app.get(/^\/$/, (req, res) => {});
參考 Express Routing 文件,將路徑匹配的 regex 改為簡單的 string pattern。
範例:
原本匹配的路徑
'^/$'
,經過 path-to-regexp 後會變成/^\^\/\$(?:\/)?$/i
,修改為/
,轉換後則是/^\/(?:\/)?$/i
。如果要直接使用 regex,可改寫為