-
-
Save mubaidr/6097b16e91985c05e240094e5245fd05 to your computer and use it in GitHub Desktop.
Revisions
-
atinux revised this gist
Jul 3, 2023 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,7 +17,6 @@ export default defineEventHandler(async (event) => { myHooks.hook('sse:event', sendEvent) // Let the connection opened event._handled = true; }) -
atinux revised this gist
Apr 21, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ // ~/server/api/sse.ts export default defineEventHandler(async (event) => { if (!process.dev) return { disabled: true } -
atinux created this gist
Apr 10, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ // server/api/sse.ts export default defineEventHandler(async (event) => { if (!process.dev) return { disabled: true } // Enable SSE endpoint setHeader(event, 'cache-control', 'no-cache') setHeader(event, 'connection', 'keep-alive') setHeader(event, 'content-type', 'text/event-stream') setResponseStatus(event, 200) let counter = 0 const sendEvent = (data: any) => { event.node.res.write(`id: ${++counter}\n`); event.node.res.write(`data: ${JSON.stringify(data)}\n\n`); } myHooks.hook('sse:event', sendEvent) await new Promise((resolve) => { // Wait forever }) })