refactor(expenses): integrate caching for periodic expenses and related operations refactor(quotes): add caching for quotes retrieval and history endpoints
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import { Hono } from "hono";
|
|
import { serveStatic } from "hono/bun";
|
|
import { auth } from "./lib/auth";
|
|
import { authMiddleware } from "./lib/auth-middleware";
|
|
import { requestLogger } from "./lib/request-logger";
|
|
import { startQuoteJob } from "./modules/quotes/quote.job";
|
|
import quotesRouter from "./modules/quotes/quotes.routes";
|
|
import expensesRouter from "./modules/expenses/expenses.routes";
|
|
import { startExpenseJob } from "./modules/expenses/expense.job";
|
|
import { cache } from "./lib/cache";
|
|
import { eventBus } from "./lib/event-bus";
|
|
import { logger } from "./lib/logger";
|
|
|
|
const app = new Hono();
|
|
|
|
app.use("*", requestLogger);
|
|
|
|
app.get("/api/health", (c) => {
|
|
return c.json({ status: "ok", timestamp: new Date().toISOString() });
|
|
});
|
|
|
|
app.on(["POST", "GET"], "/api/auth/*", (c) => auth.handler(c.req.raw));
|
|
|
|
app.use("/api/*", async (c, next) => {
|
|
if (c.req.path === "/api/health" || c.req.path.startsWith("/api/auth")) {
|
|
return next();
|
|
}
|
|
return authMiddleware(c, next);
|
|
});
|
|
|
|
app.route("/api/quotes", quotesRouter);
|
|
app.route("/api", expensesRouter);
|
|
|
|
app.use("/assets/*", serveStatic({ root: "./web" }));
|
|
app.get("*", serveStatic({ path: "./web/index.html" }));
|
|
|
|
eventBus.on("quotes-updated", () => {
|
|
cache.invalidateByPrefix("quotes:");
|
|
});
|
|
|
|
startQuoteJob();
|
|
startExpenseJob();
|
|
|
|
logger.info("Backend started");
|
|
|
|
export default app;
|