mirror of
https://github.com/FranP-code/Reflecto.git
synced 2025-10-13 00:43:31 +00:00
Add logger utility and integrate Docker Compose startup in development
This commit is contained in:
@@ -5,11 +5,28 @@ import { appRouter } from "./routers/index";
|
|||||||
import { auth } from "./lib/auth";
|
import { auth } from "./lib/auth";
|
||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
import { cors } from "hono/cors";
|
import { cors } from "hono/cors";
|
||||||
import { logger } from "hono/logger";
|
import { logger as honoLogger } from "hono/logger";
|
||||||
|
|
||||||
|
import { join } from "node:path";
|
||||||
|
import { execSync } from "node:child_process";
|
||||||
|
import { logger } from "./lib/logger";
|
||||||
|
|
||||||
const app = new Hono();
|
const app = new Hono();
|
||||||
|
|
||||||
app.use(logger());
|
if (process.env.NODE_ENV === "development") {
|
||||||
|
try {
|
||||||
|
const composePath = join(process.cwd(), "docker-compose.yml");
|
||||||
|
execSync(`docker-compose -f ${composePath} up -d`, { stdio: "inherit" });
|
||||||
|
logger.info("Waiting for services to start...");
|
||||||
|
execSync("sleep 2");
|
||||||
|
logger.info("Docker Compose started successfully");
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Failed to start Docker Compose:", error);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
app.use(honoLogger());
|
||||||
app.use(
|
app.use(
|
||||||
"/*",
|
"/*",
|
||||||
cors({
|
cors({
|
||||||
|
|||||||
32
apps/server/src/lib/logger.ts
Normal file
32
apps/server/src/lib/logger.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/* eslint-disable no-console */
|
||||||
|
|
||||||
|
export const logger = {
|
||||||
|
info: (...args: unknown[]) => {
|
||||||
|
if (process.env.NODE_ENV !== "development") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// biome-ignore lint/suspicious/noConsole: I want to use console
|
||||||
|
console.info(...args);
|
||||||
|
},
|
||||||
|
warn: (...args: unknown[]) => {
|
||||||
|
if (process.env.NODE_ENV !== "development") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// biome-ignore lint/suspicious/noConsole: I want to use console
|
||||||
|
console.warn(...args);
|
||||||
|
},
|
||||||
|
error: (...args: unknown[]) => {
|
||||||
|
if (process.env.NODE_ENV !== "development") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// biome-ignore lint/suspicious/noConsole: I want to use console
|
||||||
|
console.error(...args);
|
||||||
|
},
|
||||||
|
debug: (...args: unknown[]) => {
|
||||||
|
if (process.env.NODE_ENV !== "development") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// biome-ignore lint/suspicious/noConsole: I want to use console
|
||||||
|
console.debug(...args);
|
||||||
|
},
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user