Closed jeange1003 closed 7 years ago
Hi @jeange1003 I'm not sure I understand what you're saying. Can you perhaps provide the following?
Thanks!
The title of the issue is
Middleware is used on every request if the parameter "route" is '/'
Which is just describing exactly how connect is supposed to work, so perhaps this is just a misunderstanding of how to use connect.
Sorry, I misunderstood the connect usage. How to set the route if the middleware is just for '/', not for '/foo', '/xxx'?
Hi @jeange1003 you can't; that is not a feature of connect
unless you use some routing middleware on top, like https://github.com/pillarjs/router :
var connect = require('connect');
var router = require('router');
var app = connect();
var router = router();
// Mount a router
app.use(router);
// respond to only / requests
router.get('/', function(req, res){
res.end('Hello from Connect!\n');
});
app.listen(3000);
Got it, thank you.
In the source code https://github.com/senchalabs/connect/blob/master/index.js line 101:
// strip trailing slash if (path[path.length - 1] === '/') { path = path.slice(0, -1); }
Which changes the path from '/' to ''. If I want to run the middleware just for homepage which path is '/', I have to pass '//' for parameter "router'.