Propuesta: Abstracción nativa/wrapper en Express para simplificar el manejo de respuestas SSE (Server-Sent Events)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Quiet
- Tech stack
- express, javascript, node.js
Research direction
The issue names no repository files or tests and provides only application-level setupSse, sendSse, and handlePreStreamError examples. Start by reviewing Express's existing response API and define the supported SSE abstraction, lifecycle, and error behavior; focused tests and an agreed API would mark the work complete.
Written by the indexing model from the issue text.
Description
actualmente estoy realizando un proyecto con express, no quiero usar websockets porque solo es un endpoint específico de mi app de express que necesita que se muestre la información en tiempo real, entonces una alternativa para ello es usar sse, que es también http pero da un funcionamiento parecido al de websocket, el problema es que implementarlo requiere un setup bastante riguroso en node, siento que se podría crear una abstracción en express para hacerlo mas facil asi como con las respuestas y esas cosas, porque actualmente para poder implementarlo tengo que configurar varios headers y el sistema de envió que siento que express puede simplificar mucho creando un wrapper para el envio de respuestas con sse, aqui adjunto un ejemplo del codigo que uso en mi app el cual es un wrapper para enviar respuestas por sse de manera facil
function handlePreStreamError(res, error) {
if (res.headersSent) {
sendSse(res, {
type: "error",
code: error.code || "SERVER_INTERNAL_ERROR",
message: error.message || "Error interno del servidor",
});
return res.end();
}
return sendDomainError(res, error);
}
function sendSse(res, payload) {
res.write(`data: ${JSON.stringify(payload)}\n\n`);
res.flush?.();
}
function setupSse(res) {
res.setHeader('Content-Type', 'text/event-stream; charset=utf-8');
res.setHeader('Cache-Control', 'no-cache, no-transform');
res.setHeader('Connection', 'keep-alive');
res.setHeader('X-Accel-Buffering', 'no');
res.flushHeaders?.();
}
ejemplo de uso relativo:
async function streamResponseController(req, res) {
try {
setupSse(res);
sendSse(res, { type: "start", message: "Iniciando proceso..." });
const data = await mockDataFunction(req.body);
for await (const chunk of data) {
if (res.writableEnded || req.aborted) {
break;
}
sendSse(res, {
type: "chunk",
data: chunk,
});
}
sendSse(res, { type: "done" });
res.end();
} catch (error) {
handlePreStreamError(res, error);
}
}
- Dominant language
- JavaScript
- Stars
- 69.7k
- Forks
- 25.6k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 4
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from expressjs/express
-
Outdated res.send() syntax in lib/response.js documentation exampleMay be free again A pull request for this issue was closed without being merged. Opendocs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
expressjs/express#7588 · 1 comment ·
Maintainers usually reply within 1 day
-
4.x deps module:body-parser
Difficulty 1/5 Under an hour Newbie friendliness 75/100
expressjs/express#7564 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Update to mocha 12.xPossibly taken @ganeshghutukade-04 claimed this 26 days ago. Opendeps
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
expressjs/express#7547 · 6 comments ·
Maintainers usually reply within 1 day
-
req.subdomains splits an IPv6 host that contains dotsPossibly taken @johnnyhuirilef claimed this 30 days ago. Open4.x 5.x bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
expressjs/express#7532 · 2 comments ·
Maintainers usually reply within 1 day
-
Readme: project name 'express.js' is not capitalizedMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 1/5 Under an hour Newbie friendliness 95/100
Maintainers usually reply within 1 day
All issues in expressjs/express
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
OWASP/CheatSheetSeries#3018 ·
Maintainers usually reply within 1 day
-
Radix number block generates NaN after switching a negative or decimal number to binary, octal or hexPossibly taken @matthewalberto claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
mit-cml/appinventor-sources#4246 · 1 comment ·
Maintainers usually reply within 1 day
-
marketing
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 83/100
GoogleChrome/modern-web-guidance-src#3675 · 2 comments ·
Maintainers usually reply within 1 day