52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
|
|
import "dotenv/config";
|
||
|
|
import { Hono } from "hono";
|
||
|
|
import { serve } from "@hono/node-server";
|
||
|
|
import { cors } from "hono/cors";
|
||
|
|
|
||
|
|
import { prisma } from "./infrastructure/prisma/client.js";
|
||
|
|
import { PrismaTaskRepository } from "./infrastructure/task/prisma-task.repository.js";
|
||
|
|
import { PrismaStateRepository } from "./infrastructure/state/prisma-state.repository.js";
|
||
|
|
import { TaskService } from "./application/task/task.service.js";
|
||
|
|
import { StateService } from "./application/state/state.service.js";
|
||
|
|
import { createApiRouter } from "./presentation/routes.js";
|
||
|
|
import { errorHandler } from "./presentation/middleware/error-handler.js";
|
||
|
|
import { logger } from "./presentation/middleware/logger.js";
|
||
|
|
|
||
|
|
const taskRepository = new PrismaTaskRepository(prisma);
|
||
|
|
const stateRepository = new PrismaStateRepository(prisma);
|
||
|
|
|
||
|
|
const taskService = new TaskService(taskRepository, stateRepository);
|
||
|
|
const stateService = new StateService(stateRepository);
|
||
|
|
|
||
|
|
const app = new Hono();
|
||
|
|
|
||
|
|
const isProduction = process.env.NODE_ENV === "production";
|
||
|
|
|
||
|
|
app.use(
|
||
|
|
"*",
|
||
|
|
cors({
|
||
|
|
origin: isProduction ? "https://emi.challenge.berand97.dev" : "*",
|
||
|
|
})
|
||
|
|
);
|
||
|
|
app.use("*", logger);
|
||
|
|
app.onError(errorHandler);
|
||
|
|
|
||
|
|
app.route("/api", createApiRouter(taskService, stateService));
|
||
|
|
|
||
|
|
app.get("/", (c) => {
|
||
|
|
return c.json({
|
||
|
|
message: "Task Management API",
|
||
|
|
version: "1.0.0",
|
||
|
|
endpoints: {
|
||
|
|
tasks: "/api/tasks",
|
||
|
|
states: "/api/states",
|
||
|
|
},
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
const port = Number(process.env.PORT) || 3000;
|
||
|
|
|
||
|
|
serve({ fetch: app.fetch, port }, (info) => {
|
||
|
|
console.log(`Server running on http://localhost:${info.port}`);
|
||
|
|
});
|