Refactor API and worker applications to use NestJS framework. Update package versions and scripts for improved functionality. Enhance TypeScript configurations and add new dependencies for better development support. Remove deprecated main.ts file from worker application.
This commit is contained in:
@@ -39,7 +39,8 @@ export class Rfc7807ExceptionFilter implements ExceptionFilter {
|
||||
instance: string,
|
||||
): ProblemDetails {
|
||||
if (exception instanceof HttpException) {
|
||||
const response = exception.getResponse();
|
||||
const httpException = exception;
|
||||
const response = httpException.getResponse();
|
||||
|
||||
if (typeof response === 'object' && response !== null) {
|
||||
const body = response as Record<string, unknown>;
|
||||
@@ -55,7 +56,7 @@ export class Rfc7807ExceptionFilter implements ExceptionFilter {
|
||||
|
||||
if (typeof body['message'] === 'string') {
|
||||
return createProblemDetails({
|
||||
title: exception.name,
|
||||
title: httpException.name,
|
||||
status,
|
||||
detail: body['message'],
|
||||
instance,
|
||||
@@ -68,7 +69,7 @@ export class Rfc7807ExceptionFilter implements ExceptionFilter {
|
||||
status,
|
||||
detail: 'Request validation failed',
|
||||
instance,
|
||||
errors: body['message'].map((message) => ({
|
||||
errors: body['message'].map((message: unknown) => ({
|
||||
message: String(message),
|
||||
})),
|
||||
});
|
||||
@@ -76,9 +77,9 @@ export class Rfc7807ExceptionFilter implements ExceptionFilter {
|
||||
}
|
||||
|
||||
return createProblemDetails({
|
||||
title: exception.name,
|
||||
title: httpException.name,
|
||||
status,
|
||||
detail: exception.message,
|
||||
detail: httpException.message,
|
||||
instance,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,26 +1,48 @@
|
||||
import http from "node:http";
|
||||
import { randomUUID } from 'node:crypto';
|
||||
|
||||
const port = Number(process.env.API_PORT ?? 3001);
|
||||
const appName = process.env.APP_NAME ?? "HexaHost GameCloud";
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import {
|
||||
FastifyAdapter,
|
||||
NestFastifyApplication,
|
||||
} from '@nestjs/platform-fastify';
|
||||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
||||
import { Logger } from 'nestjs-pino';
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
if (req.url === "/healthz" || req.url === "/health") {
|
||||
res.writeHead(200, { "Content-Type": "application/json" });
|
||||
res.end(
|
||||
JSON.stringify({
|
||||
status: "ok",
|
||||
service: "api",
|
||||
app: appName,
|
||||
phase: "0",
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
import { validateConfig } from '@hexahost/config';
|
||||
|
||||
res.writeHead(404, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify({ status: "not_found" }));
|
||||
});
|
||||
import { AppModule } from './app.module';
|
||||
import { Rfc7807ExceptionFilter } from './common/filters/rfc7807-exception.filter';
|
||||
|
||||
server.listen(port, () => {
|
||||
console.log(JSON.stringify({ level: "info", msg: "api listening", port }));
|
||||
});
|
||||
async function bootstrap(): Promise<void> {
|
||||
const config = validateConfig();
|
||||
|
||||
const app = await NestFactory.create<NestFastifyApplication>(
|
||||
AppModule,
|
||||
new FastifyAdapter({
|
||||
genReqId: () => randomUUID(),
|
||||
requestIdHeader: 'x-request-id',
|
||||
requestIdLogLabel: 'requestId',
|
||||
}),
|
||||
{
|
||||
bufferLogs: true,
|
||||
},
|
||||
);
|
||||
|
||||
app.useLogger(app.get(Logger));
|
||||
app.setGlobalPrefix('api/v1');
|
||||
app.useGlobalFilters(new Rfc7807ExceptionFilter());
|
||||
|
||||
const swaggerConfig = new DocumentBuilder()
|
||||
.setTitle(config.APP_NAME)
|
||||
.setDescription('HexaHost GameCloud REST API')
|
||||
.setVersion('0.0.0')
|
||||
.addServer(config.API_URL)
|
||||
.build();
|
||||
|
||||
const document = SwaggerModule.createDocument(app, swaggerConfig);
|
||||
SwaggerModule.setup('api/v1/docs', app, document);
|
||||
|
||||
await app.listen(config.API_PORT, '0.0.0.0');
|
||||
}
|
||||
|
||||
void bootstrap();
|
||||
|
||||
Reference in New Issue
Block a user