feat: add build
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { type FastifyPluginAsync } from 'fastify';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { manageEndpoints } from './endpoints/endpoints.manage.ts';
|
||||
import { authPlugin } from './plugins/plugins.auth.ts';
|
||||
import { messageEndpoints } from './endpoints/endpoints.message.ts';
|
||||
import { z } from 'zod';
|
||||
|
||||
const api: FastifyPluginAsync = async (fastify) => {
|
||||
fastify.route({
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import type { FastifyPluginAsyncZod } from 'fastify-type-provider-zod';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { JwtAuth } from '#root/auth/auth.jwt.ts';
|
||||
import { statementSchema } from '#root/auth/auth.schemas.ts';
|
||||
import { Config } from '#root/config/config.ts';
|
||||
import type { FastifyPluginAsyncZod } from 'fastify-type-provider-zod';
|
||||
import { z } from 'zod';
|
||||
|
||||
const manageEndpoints: FastifyPluginAsyncZod = async (fastify) => {
|
||||
const config = fastify.services.get(Config);
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { Config } from '#root/config/config.ts';
|
||||
import { MqttServer } from '#root/server/server.ts';
|
||||
import type { FastifyPluginAsyncZod } from 'fastify-type-provider-zod';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { Config } from '#root/config/config.ts';
|
||||
import { MqttServer } from '#root/server/server.ts';
|
||||
|
||||
const messageEndpoints: FastifyPluginAsyncZod = async (fastify) => {
|
||||
const config = fastify.services.get(Config);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { SessionProvider } from '#root/services/sessions/sessions.provider.ts';
|
||||
import type { FastifyPluginAsyncZod } from 'fastify-type-provider-zod';
|
||||
|
||||
import { SessionProvider } from '#root/services/sessions/sessions.provider.ts';
|
||||
|
||||
const authPlugin: FastifyPluginAsyncZod = async (fastify) => {
|
||||
fastify.addHook('onRequest', async (req, reply) => {
|
||||
const authProvider = req.headers['x-auth-provider'];
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import type { Services } from '#root/utils/services.ts';
|
||||
import { Config } from '#root/config/config.ts';
|
||||
import type { AuthProvider } from './auth.provider.ts';
|
||||
import { ADMIN_STATEMENTS } from './auth.consts.ts';
|
||||
|
||||
import type { Services } from '#root/utils/services.ts';
|
||||
import { Config } from '#root/config/config.ts';
|
||||
|
||||
class AdminAuth implements AuthProvider {
|
||||
#services: Services;
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@ import jwt from 'jsonwebtoken';
|
||||
|
||||
import type { Statement } from './auth.schemas.ts';
|
||||
import type { AuthProvider } from './auth.provider.ts';
|
||||
import { ADMIN_STATEMENTS, READER_STATEMENTS, WRITER_STATEMENTS } from './auth.consts.ts';
|
||||
|
||||
import type { Services } from '#root/utils/services.ts';
|
||||
import { Config } from '#root/config/config.ts';
|
||||
import { ADMIN_STATEMENTS, READER_STATEMENTS, WRITER_STATEMENTS } from './auth.consts.ts';
|
||||
|
||||
class OidcAuth implements AuthProvider {
|
||||
#services: Services;
|
||||
|
||||
@@ -59,7 +59,7 @@ class Config {
|
||||
}
|
||||
|
||||
public get tcp() {
|
||||
const enabled = (process.env.TCP_ENABLED = 'true');
|
||||
const enabled = process.env.TCP_ENABLED === 'true';
|
||||
const port = process.env.TCP_PORT ? parseInt(process.env.TCP_PORT) : 1883;
|
||||
return {
|
||||
enabled,
|
||||
|
||||
@@ -2,13 +2,7 @@ import tcp from 'node:net';
|
||||
import type { IncomingMessage } from 'node:http';
|
||||
|
||||
import swagger from '@fastify/swagger';
|
||||
import type { ZodTypeProvider } from 'fastify-type-provider-zod';
|
||||
import {
|
||||
jsonSchemaTransform,
|
||||
createJsonSchemaTransform,
|
||||
serializerCompiler,
|
||||
validatorCompiler,
|
||||
} from 'fastify-type-provider-zod';
|
||||
import { jsonSchemaTransform, serializerCompiler, validatorCompiler } from 'fastify-type-provider-zod';
|
||||
import scalar from '@scalar/fastify-api-reference';
|
||||
import {
|
||||
type AuthenticateHandler,
|
||||
@@ -21,14 +15,14 @@ import aedes from 'aedes';
|
||||
import fastify, { type FastifyInstance } from 'fastify';
|
||||
import fastifyWebSocket from '@fastify/websocket';
|
||||
import { createWebSocketStream } from 'ws';
|
||||
import fastifySensible from '@fastify/sensible';
|
||||
|
||||
import { api } from '../api/api.ts';
|
||||
|
||||
import { TopicsHandler } from '#root/topics/topics.handler.ts';
|
||||
import type { Services } from '#root/utils/services.ts';
|
||||
import { destroy, type Services } from '#root/utils/services.ts';
|
||||
import { Session } from '#root/services/sessions/sessions.session.ts';
|
||||
import { SessionProvider } from '#root/services/sessions/sessions.provider.ts';
|
||||
import fastifySensible from '@fastify/sensible';
|
||||
import { Config } from '#root/config/config.ts';
|
||||
|
||||
type Aedes = ReturnType<typeof aedes.createBroker>;
|
||||
@@ -188,6 +182,25 @@ class MqttServer {
|
||||
}
|
||||
return this.#tcp;
|
||||
};
|
||||
|
||||
[destroy] = async () => {
|
||||
if (this.#http) {
|
||||
const http = await this.#http;
|
||||
await http.close();
|
||||
}
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
if (this.#tcp) {
|
||||
this.#tcp.close((err) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export { MqttServer };
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { AuthProvider } from '#root/auth/auth.provider.ts';
|
||||
import { Session } from './sessions.session.ts';
|
||||
|
||||
import type { AuthProvider } from '#root/auth/auth.provider.ts';
|
||||
|
||||
class SessionProvider {
|
||||
#handlers: Map<string, AuthProvider>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user