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.
如何创建在所有不提供静态文件的 url 上运行的中间件?
我正在考虑检查是否req.url不以“/js/”、“/css/”或“/images/”开头,但必须有更好的方法
req.url
最简单(也是最快)的方法是将静态文件中间件放在“包罗万象”中间件之前:
app.use(express.static(STATIC_DIR_HERE)); app.use(function notStatic(req, res, next) { // everything here will be non-static routes });
(app你的快递实例在哪里)
app