You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use browser-sync as the server in my project since v2.18.13. Yesterday, I reinstalled my project. When I run it, the cli print:
_http_outgoing.js:494
throw new Error('Can\'t set headers after they are sent.');
env
Browsersync [ 2.23.2 and 2.21.0 ]
Node [ 8.9.3 ]
windows 7
Git Bash
test case
// const browserSync = require('../bs/node_modules/browser-sync/'); // for bs 2.23.2constbrowserSync=require('../bs21/node_modules/browser-sync/');// for bs 2.21.0letbs=browserSync.create('bsServer');bs.init({server: '',open: true,middleware: [mw]});functionmw(request,response,next){response.write('bs');response.end();next();}
when use v2.23.2, the server will stop, and throw the error below.
v2.21.0 works fine.
_http_outgoing.js:494
throw new Error('Can\'t set headers after they are sent.');
^
Error: Can't set headers after they are sent.
at validateHeader (_http_outgoing.js:494:11)
at ServerResponse.setHeader (_http_outgoing.js:501:3)
at D:\TMP\bs\node_modules\serve-index\index.js:213:13
at D:\TMP\bs\node_modules\serve-index\index.js:324:7
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)
I cannot call response.end or response.write method in my middleware.
If I have to call these methods, I have to remove the next() method. This seems to prevent the middleware flow.
I want to know how this problem arises, thanks!
The text was updated successfully, but these errors were encountered:
I've pushed a fix that will work for you when doing the example above
Note: It will still not work if you do something like server: 'app' as this will append a server-static middleware to the end of the stack and will result in the same bug
I use browser-sync as the server in my project since v2.18.13. Yesterday, I reinstalled my project. When I run it, the cli print:
env
test case
when use v2.23.2, the server will stop, and throw the error below.
v2.21.0 works fine.
I cannot call
response.end
orresponse.write
method in my middleware.If I have to call these methods, I have to remove the
next()
method. This seems to prevent the middleware flow.I want to know how this problem arises, thanks!
The text was updated successfully, but these errors were encountered: