senchalabs / connect

Connect is a middleware layer for Node.js
MIT License
9.84k stars 1.09k forks source link

fix: router to correct work with first / route and others #1123

Closed dkatashev closed 4 years ago

dkatashev commented 5 years ago

This PR fix the problem associated with the route / and rest routes. In order to reproduce the problem, you can use the code below, which will cause the router /body to stop being called without this fix.

const connect = require('connect');

const app = connect();

app.use('/', (req, res, next) => {
    const { headers, method, body } = req;

    res.writeHead(200, { 'Content-Type': 'application/json' });
    res.end(JSON.stringify({ headers, method, body }, null, 2));

    next();
});

app.use('/body', (req, res, next) => {
    const { body } = req;

    res.writeHead(200, { 'Content-Type': 'application/json' });
    res.end(JSON.stringify({ body }, null, 2));

    next();
});
dougwilson commented 4 years ago

Closing due to no response.