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:
@@ -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