I have the following code that works fine in node v0.10.28.
app.use(function (req, res, next) { if (req.path === "/" || req.path === "/index.html") { var token = req.cookies && req.cookies.token ? req.cookies.token : undefined; if (token) { next(); } else { console.log("Request url is....................." + req.url); console.log("time while redirecting to login...." + new Date()); console.log("userAgents........" + req.headers['user-agent']); try { res.redirect('/login'); } catch (error) { console.log("error....." + error.message); } } } else { next(); } });
But after switching to node v0.12.7 this gives an error.
Error: write after end at ServerResponse.OutgoingMessage.write (_http_outgoing.js:413:15) at ServerResponse.res.write (/node_modules/compression/index.js:87:17) at ServerResponse.res.end (/node_modules/compression/index.js:104:14) at ServerResponse.redirect (/node_modules/express/lib/response.js:846:8) at Http.js:11:21 at Layer.handle [as handle_request]
This error arrives continuously 3 times, and then repeats after an hour. Here are some of my consoles.
Request url is...................../ Time while redirecting to login....Thu Aug 06 2015 15:58:18 GMT+0000 (UTC) UserAgents........Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.67 Safari/537.36 Uncaught Err>>>>>>Error: write after end Request url is...................../ Time while redirecting to login....Thu Aug 06 2015 15:58:18 GMT+0000 (UTC) UserAgents........Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.67 Safari/537.36 Uncaught Err>>>>>>Error: write after end Request url is...................../ Time while redirecting to login....Thu Aug 06 2015 15:58:31 GMT+0000 (UTC) UserAgents........Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.67 Safari/537.36 Uncaught Err>>>>>>Error: write after end
This error does not fall into the catch block and becomes an uncaught error.
I will be very grateful for any tips on how I can solve this problem.
source share