javascript - How to use server-sent-events in express.js -
i setup rest server express.js. want add sse server. after implemented this sse package, error. know error, when try use res.send
twice, not.
error: error: can't set headers after sent. @ serverresponse.outgoingmessage.setheader (http.js:690:11) @ serverresponse.header (/home/root/node_modules/express/lib/response.js:718:10) @ serverresponse.send (/home/root/node_modules/express/lib/response.js:163:12) @ app.get.str (/home/root/.node_app_slot/main.js:1330:25) @ layer.handle [as handle_request] (/home/root/node_modules/express/lib/router/layer.js:95:5) @ next (/home/root/node_modules/express/lib/router/route.js:131:13) @ sse (/home/root/node_modules/server-sent-events/index.js:35:2) @ layer.handle [as handle_request] (/home/root/node_modules/express/lib/router/layer.js:95:5) @ next (/home/root/node_modules/express/lib/router/route.js:131:13) @ route.dispatch (/home/root/node_modules/express/lib/router/route.js:112:3)
is possible can't use express methods anymore within sse function? example:
app.get('/events', sse, function(req, res) { res.send('...'); });
furthermore, found this solution , this. possible make sse res.write
function or in way without using package?
you can achieve without other packages.
i wrote blog post this, part 1 sets out basics.
Comments
Post a Comment