next and nest

This commit is contained in:
Emmanuel Rojas committed 2026-09-22 14:08:17 -05:00
1 parent 55f69fbbb4
commit 90125aede9
30 files changed
+3754 -344

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
import { Controller, Get } from "@nestjs/common";
import { AppService } from "./app.service";
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get("health")
getHealth() {
return this.appService.getHealth();
}
}
+10
View File
@@ -0,0 +1,10 @@
import { Module } from "@nestjs/common";
import { AppController } from "./app.controller";
import { AppService } from "./app.service";
@Module({
imports: [],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
+8
View File
@@ -0,0 +1,8 @@
import { Injectable } from "@nestjs/common";
@Injectable()
export class AppService {
getHealth() {
return { status: "ok" };
}
}
+35
View File
@@ -0,0 +1,35 @@
import "reflect-metadata";
import path from "node:path";
import { NestFactory } from "@nestjs/core";
import type { NestExpressApplication } from "@nestjs/platform-express";
import next from "next";
import { AppModule } from "./app.module";
async function bootstrap() {
const dev = process.env.NODE_ENV !== "production";
const port = Number(process.env.PORT ?? 3000);
// apps/api siempre corre compilado desde dist/, por lo que apps/web
// queda dos niveles arriba tanto en desarrollo como en producción.
const nextApp = next({ dev, dir: path.join(__dirname, "../../web") });
const handleNextRequest = nextApp.getRequestHandler();
await nextApp.prepare();
const app = await NestFactory.create<NestExpressApplication>(AppModule);
app.setGlobalPrefix("api");
// Se inicializa antes de registrar el catch-all para que las rutas de
// Nest queden montadas primero y Next solo reciba lo que Nest no maneja.
await app.init();
app
.getHttpAdapter()
.getInstance()
.all(/.*/, (req, res) => handleNextRequest(req, res));
await app.listen(port);
console.log(
`> Servidor listo en http://localhost:${port} (${dev ? "development" : "production"})`,
);
}
void bootstrap();