简体   繁体   English

Express.js:如何使express.static的优先级高于应用程序的其他部分?

[英]Express.js: how to make express.static have higher priority than the rest of the app?

I have an express.js app set up like this: 我有一个像这样设置的express.js应用程序:

app.use(express.static(__dirname + '/public'));
...
app.all('*', require('./routes/all'));

So when I try to load /stylesheets/style.css , request is dispatched to the routes . 因此,当我尝试加载/stylesheets/style.css/stylesheets/style.css请求分派给routes How do I make the app first try to use "static", and then - the catch-all route? 如何让应用程序首先尝试使用“静态”,然后 - 全能路线?

Middleware get executed in sequential order. 中间件按顺序执行。 Simply put the static middleware before the routing middleware. 简单地将静态中间件放在路由中间件之前。

app.configure(function() {
  app.use(express.static(__dirname + '/public'));
  app.use(app.router);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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