Middleware invoking next() instead of res.end()