server side events and ui improvemnt

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-02-09 15:05:59 +01:00
parent 04453c673f
commit 484a6b1d41
73 changed files with 1095 additions and 650 deletions

View File

@@ -1,9 +1,12 @@
import cors from '@fastify/cors';
import Fastify from 'fastify';
import { FastifySSEPlugin } from 'fastify-sse-v2';
import pino from 'pino';
import { redisPub } from '@mixan/redis';
import eventRouter from './routes/event.router';
import { validateSdkRequest } from './utils/auth';
import liveRouter from './routes/live.router';
declare module 'fastify' {
interface FastifyRequest {
@@ -23,22 +26,10 @@ const startServer = async () => {
origin: '*',
});
fastify.register(FastifySSEPlugin);
fastify.decorateRequest('projectId', '');
fastify.addHook('preHandler', (req, reply, done) => {
validateSdkRequest(req.headers)
.then((projectId) => {
req.projectId = projectId;
done();
})
.catch((e) => {
console.log(e);
reply.status(401).send();
});
});
fastify.register(eventRouter, { prefix: '/event' });
fastify.register(liveRouter, { prefix: '/live' });
fastify.setErrorHandler((error, request, reply) => {
fastify.log.error(error);
});
@@ -65,6 +56,9 @@ const startServer = async () => {
}
await fastify.listen({ host: '0.0.0.0', port });
// Notify when keys expires
redisPub.config('SET', 'notify-keyspace-events', 'Ex');
} catch (e) {
console.error(e);
}