Skip to content

Commit 9e75a89

Browse files
author
Lasim
committed
feat(backend): add SSE plugin with heartbeat interval for server events
1 parent 46a6855 commit 9e75a89

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

package-lock.json

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

services/backend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"@fastify/cors": "^11.1.0",
2525
"@fastify/formbody": "^8.0.2",
2626
"@fastify/rate-limit": "^10.3.0",
27+
"@fastify/sse": "^0.4.0",
2728
"@fastify/swagger": "^9.6.1",
2829
"@fastify/swagger-ui": "^5.2.3",
2930
"@lucia-auth/adapter-drizzle": "^1.1.0",

services/backend/src/fastify/plugins/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { FastifyInstance } from 'fastify'
22
import fastifyCors from '@fastify/cors'
33
import fastifyFormbody from '@fastify/formbody'
44
import fastifyRateLimit from '@fastify/rate-limit'
5+
import fastifySSE from '@fastify/sse'
56

67
export const registerFastifyPlugins = async (server: FastifyInstance): Promise<void> => {
78
// Build allowed origins array
@@ -38,6 +39,12 @@ export const registerFastifyPlugins = async (server: FastifyInstance): Promise<v
3839
})
3940
server.log.info('Rate limiting plugin registered (per-route configuration enabled)');
4041

42+
// Register SSE (Server-Sent Events) plugin
43+
await server.register(fastifySSE, {
44+
heartbeatInterval: 30000 // Send heartbeat every 30 seconds to keep connections alive
45+
})
46+
server.log.info('SSE plugin registered (heartbeat interval: 30s)');
47+
4148
// Favicon plugin is now registered in server.ts after Swagger to exclude it from documentation
4249

4350
// Register other plugins as needed

0 commit comments

Comments
 (0)