DenoDDeno
Powered by
jsJ
Denoβ€’10mo agoβ€’
3 replies
js

ReadableStream doesn't work in production

I'm following the Deno SSE example to set up a GET route for SSE payloads.

Exact I got from the SSE examples works ONLY in local development. In production, the requests are stuck in "pending" forever.

Is there something different about localhost and production environment that I have to change?

app.get('/test-sse', (c: Context) => {
        let timerId: number | undefined;
        const body = new ReadableStream({
            start(controller) {
                const encoder = new TextEncoder();
                timerId = setInterval(() => {
                    const streamMessage = JSON.stringify({
                        message: `Hello world ${new Date().toISOString()}`,
                    });

                    controller.enqueue(new TextEncoder().encode(`data: ${streamMessage}\r\n\r\n`));
                }, 1000);
            },
            cancel() {
                if (typeof timerId === 'number') {
                    clearInterval(timerId);
                }
            },
        });



        return new Response(body, {
            headers: {
                'Content-Type': 'text/event-stream',
                'Cache-Control': 'no-cache',
                'Connection': 'keep-alive',
            },
        });
    });
app.get('/test-sse', (c: Context) => {
        let timerId: number | undefined;
        const body = new ReadableStream({
            start(controller) {
                const encoder = new TextEncoder();
                timerId = setInterval(() => {
                    const streamMessage = JSON.stringify({
                        message: `Hello world ${new Date().toISOString()}`,
                    });

                    controller.enqueue(new TextEncoder().encode(`data: ${streamMessage}\r\n\r\n`));
                }, 1000);
            },
            cancel() {
                if (typeof timerId === 'number') {
                    clearInterval(timerId);
                }
            },
        });



        return new Response(body, {
            headers: {
                'Content-Type': 'text/event-stream',
                'Cache-Control': 'no-cache',
                'Connection': 'keep-alive',
            },
        });
    });
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,944Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Redirect doesn't work in dev mode
smolenskSsmolensk / help
3w ago
installing playwright in container doesn't work
lucsoftLlucsoft / help
17mo ago
`declare module` doesn’t work
MqxMMqx / help
2y ago
`deno.disablePaths` doesn't work
babakfpBbabakfp / help
3y ago