Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
2 つのルーターがあるとします。
app.get('blog/show', function () { todo(); }) app.get('/admin', function () { todo(); })
2 つのルーターを同じapp.get方法にマージできますかapp.get('blog/show', '/admin')?
app.get
app.get('blog/show', '/admin')
それを行う方法はありますか?
bryanmac が述べたように、どちらの場合にも一致する正規表現としてルート パスを指定することでこれを行うことができます。
app.get(/blog\/show|\/admin/, function () { todo(); });
もちろん、両方のルートで同じ名前の関数を使用することもできます。
function handler() { todo(); } app.get('blog/show', handler); app.get('/admin', handler);