next and nest
This commit is contained in:
1 parent
55f69fbbb4
commit
90125aede9
30 files changed
+3754
-344
No files matched your search
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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 {}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHealth() {
|
||||
return { status: "ok" };
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
Reference in new issue
Block a user