refactor: migrate to tsup for builds and update tsconfigs fix: update error handling and validation in payment service chore: update package scripts and dependencies docs: update README and env examples
53 lines
1.2 KiB
TypeScript
53 lines
1.2 KiB
TypeScript
import { serve } from "@hono/node-server";
|
|
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
import { swaggerUI } from "@hono/swagger-ui";
|
|
import { config } from "./config";
|
|
import { logger } from "@repo/logger";
|
|
|
|
const app = new OpenAPIHono();
|
|
|
|
// OpenAPI documentation
|
|
app.doc("/doc", {
|
|
openapi: "3.0.0",
|
|
info: {
|
|
version: "1.0.0",
|
|
title: "API Documentation",
|
|
description: "API built with Hono and Zod OpenAPI",
|
|
},
|
|
});
|
|
|
|
// Swagger UI
|
|
app.get("/ui", swaggerUI({ url: "/doc" }));
|
|
|
|
// Health check
|
|
app.get("/health", (c) => {
|
|
return c.json({ status: "ok", timestamp: new Date().toISOString() });
|
|
});
|
|
|
|
const port = parseInt(config.PORT);
|
|
|
|
logger.info(`Starting API server on port ${port}`);
|
|
logger.info(`Swagger UI available at http://localhost:${port}/ui`);
|
|
|
|
const server = serve({
|
|
fetch: app.fetch,
|
|
port,
|
|
});
|
|
|
|
const tearDown = () => {
|
|
logger.info("Server shutting down...");
|
|
if (server) {
|
|
server.close(() => {
|
|
logger.info("Server closed");
|
|
process.exit(0);
|
|
});
|
|
} else {
|
|
process.exit(0);
|
|
}
|
|
};
|
|
|
|
process.on("SIGINT", tearDown);
|
|
process.on("SIGTERM", tearDown);
|
|
process.on("SIGUSR1", tearDown);
|
|
process.on("SIGUSR2", tearDown);
|