generated from Dicken/dickendock
Erstes lauffähiges Grundgerüst: Monorepo, Fastify-API, React-Startseite, Docker
This commit is contained in:
41
apps/backend/src/index.ts
Normal file
41
apps/backend/src/index.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import Fastify from "fastify";
|
||||
import cors from "@fastify/cors";
|
||||
import { ensureSchema } from "./db/client.js";
|
||||
import { healthRoutes } from "./routes/health.js";
|
||||
|
||||
const PORT = Number(process.env.PORT ?? 3001);
|
||||
const HOST = process.env.HOST ?? "0.0.0.0";
|
||||
|
||||
async function main() {
|
||||
const app = Fastify({
|
||||
logger: {
|
||||
level: process.env.LOG_LEVEL ?? "info",
|
||||
transport:
|
||||
process.env.NODE_ENV !== "production"
|
||||
? { target: "pino-pretty", options: { colorize: true } }
|
||||
: undefined,
|
||||
},
|
||||
});
|
||||
|
||||
await app.register(cors, {
|
||||
origin: process.env.CORS_ORIGIN ?? true,
|
||||
});
|
||||
|
||||
ensureSchema();
|
||||
|
||||
await app.register(healthRoutes);
|
||||
|
||||
app.get("/", async () => {
|
||||
return { name: "LaunchPad API", status: "running" };
|
||||
});
|
||||
|
||||
try {
|
||||
await app.listen({ port: PORT, host: HOST });
|
||||
app.log.info(`LaunchPad backend läuft auf http://${HOST}:${PORT}`);
|
||||
} catch (err) {
|
||||
app.log.error(err);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user