feat: initial commit - Moraworld Imports project

This commit is contained in:
Lizandro Guarnizo
2026-06-01 08:06:40 -05:00
commit 094ea9cf81
47 changed files with 12844 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
import { Module } from "@nestjs/common";
import { ConfigModule } from "@nestjs/config";
import { HealthModule } from "./health/health.module";
import { PrismaModule } from "./prisma/prisma.module";
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
envFilePath: ["../../.env", ".env"],
}),
PrismaModule,
HealthModule,
],
})
export class AppModule {}
+27
View File
@@ -0,0 +1,27 @@
import { Controller, Get } from "@nestjs/common";
import { PrismaService } from "../prisma/prisma.service";
@Controller()
export class HealthController {
constructor(private readonly prisma: PrismaService) {}
@Get("health")
async health() {
let database: "ok" | "error" = "ok";
try {
await this.prisma.client.$queryRaw`SELECT 1`;
} catch {
database = "error";
}
return {
status: database === "ok" ? "ok" : "degraded",
service: "moraworld-api",
version: "0.1.0",
timestamp: new Date().toISOString(),
checks: {
database,
},
};
}
}
+7
View File
@@ -0,0 +1,7 @@
import { Module } from "@nestjs/common";
import { HealthController } from "./health.controller";
@Module({
controllers: [HealthController],
})
export class HealthModule {}
+24
View File
@@ -0,0 +1,24 @@
import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const corsOrigins = (process.env.CORS_ORIGINS ?? "http://localhost:3000")
.split(",")
.map((o) => o.trim());
app.enableCors({
origin: corsOrigins,
credentials: true,
});
app.setGlobalPrefix("api");
const port = process.env.API_PORT ?? process.env.PORT ?? 3001;
await app.listen(port, "0.0.0.0");
console.log(`Moraworld API → http://localhost:${port}/api`);
}
bootstrap();
+9
View File
@@ -0,0 +1,9 @@
import { Global, Module } from "@nestjs/common";
import { PrismaService } from "./prisma.service";
@Global()
@Module({
providers: [PrismaService],
exports: [PrismaService],
})
export class PrismaModule {}
+15
View File
@@ -0,0 +1,15 @@
import { Injectable, OnModuleDestroy, OnModuleInit } from "@nestjs/common";
import { prisma, PrismaClient } from "@moraworld/database";
@Injectable()
export class PrismaService implements OnModuleInit, OnModuleDestroy {
readonly client: PrismaClient = prisma;
async onModuleInit() {
await prisma.$connect();
}
async onModuleDestroy() {
await prisma.$disconnect();
}
}