refact: use service container

This commit is contained in:
Morten Olsen
2025-10-16 12:13:22 +02:00
parent 8e594d59fd
commit 1f4b9cab04
12 changed files with 657 additions and 143 deletions

View File

@@ -8,6 +8,7 @@ import { MqttServer } from '#root/server/server.ts';
import type { TopicDefinition } from '#root/topics/topcis.schemas.ts';
import { TopicsHandler } from '#root/topics/topics.handler.ts';
import { TopicsStore } from '#root/topics/topics.store.ts';
import { Backbone } from '#root/backbone.ts';
type CreateSocketOptions = {
port: number;
@@ -30,17 +31,16 @@ type WorldOptions = {
const createWorld = async (options: WorldOptions) => {
const { topics = [] } = options;
const backbone = new Backbone();
const secret = 'test';
const accessHandler = new AccessHandler();
const accessTokens = new AccessTokens({
secret,
});
accessHandler.register('token', accessTokens);
const topicsHandler = new TopicsHandler();
backbone.accessHandler.register('token', accessTokens);
const topicsStore = new TopicsStore();
topicsStore.register(...topics);
topicsHandler.register(topicsStore);
const server = new MqttServer({ topicsHandler, accessHandler });
backbone.topicsHandler.register(topicsStore);
const server = backbone.server;
const fastify = await server.getHttpServer();
const port = await getPort();
await fastify.listen({ port });