2026-06-01 21:44:29 +07:00
|
|
|
import express, {
|
|
|
|
|
type Express,
|
|
|
|
|
type NextFunction,
|
|
|
|
|
type Request,
|
|
|
|
|
type Response,
|
|
|
|
|
} from "express";
|
|
|
|
|
import helmet from "helmet";
|
2026-08-01 22:09:02 +07:00
|
|
|
import { createChildLogger } from "@/shared/logger/index";
|
2026-07-27 21:54:31 +07:00
|
|
|
import { createAnalysisRouter } from "../modules/analysis/index.js";
|
2026-08-01 22:09:02 +07:00
|
|
|
import { createChatbotRouter } from "../modules/chatbot/index.js";
|
2026-07-27 21:54:31 +07:00
|
|
|
import { createConfigRouter } from "../modules/config/index.js";
|
|
|
|
|
import { createDashboardRouter } from "../modules/dashboard/index.js";
|
|
|
|
|
import { createHealthRouter } from "../modules/health/index.js";
|
|
|
|
|
import { createMediaRouter } from "../modules/media/index.js";
|
|
|
|
|
import { createMessagesRouter } from "../modules/messages/index.js";
|
|
|
|
|
import { createRecordingsRouter } from "../modules/recordings/index.js";
|
|
|
|
|
import { createUiStateRouter } from "../modules/ui-state/index.js";
|
|
|
|
|
import { createVoiceRouter } from "../modules/voice/index.js";
|
2026-07-26 11:33:45 +07:00
|
|
|
import { errorHandler } from "../shared/middlewares/index.js";
|
2026-06-13 14:10:34 +07:00
|
|
|
|
2026-07-26 11:33:45 +07:00
|
|
|
// Auth removed — dashboard is public
|
2026-07-02 03:54:44 +07:00
|
|
|
|
2026-06-01 21:44:29 +07:00
|
|
|
const logger = createChildLogger("http.app");
|
|
|
|
|
|
|
|
|
|
export function createHttpApp(): Express {
|
|
|
|
|
const app = express();
|
|
|
|
|
|
|
|
|
|
// Security middleware
|
|
|
|
|
app.use(
|
|
|
|
|
helmet({
|
|
|
|
|
contentSecurityPolicy: false,
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Body parsing
|
|
|
|
|
app.use(express.json());
|
|
|
|
|
app.use(express.urlencoded({ extended: true }));
|
|
|
|
|
|
|
|
|
|
// Request logging
|
|
|
|
|
app.use((req: Request, res: Response, next: NextFunction) => {
|
|
|
|
|
if (req.path.startsWith("/api/")) {
|
|
|
|
|
res.set("Cache-Control", "no-store");
|
|
|
|
|
}
|
|
|
|
|
res.on("finish", () => {
|
|
|
|
|
if (req.originalUrl.startsWith("/.well-known/")) return;
|
|
|
|
|
if (req.originalUrl === "/favicon.ico") return;
|
|
|
|
|
if (res.statusCode >= 400) {
|
|
|
|
|
logger.warn(
|
|
|
|
|
{
|
|
|
|
|
method: req.method,
|
|
|
|
|
url: req.originalUrl,
|
|
|
|
|
statusCode: res.statusCode,
|
|
|
|
|
},
|
|
|
|
|
"HTTP request failed",
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
|
2026-07-26 11:33:45 +07:00
|
|
|
// All routes are public
|
2026-06-01 21:44:29 +07:00
|
|
|
app.use("/api", createHealthRouter());
|
2026-06-02 00:11:29 +07:00
|
|
|
app.use("/api", createConfigRouter());
|
2026-06-13 11:24:42 +07:00
|
|
|
app.use("/api", createDashboardRouter());
|
2026-07-02 06:51:57 +07:00
|
|
|
app.use("/api", createMessagesRouter());
|
|
|
|
|
app.use("/api", createAnalysisRouter());
|
2026-07-28 15:00:29 +07:00
|
|
|
app.use("/api", createChatbotRouter());
|
2026-07-02 06:51:57 +07:00
|
|
|
app.use("/api", createRecordingsRouter());
|
|
|
|
|
app.use("/api", createUiStateRouter());
|
2026-07-26 11:33:45 +07:00
|
|
|
app.use("/api", createMediaRouter());
|
|
|
|
|
app.use("/api", createVoiceRouter());
|
2026-06-01 21:44:29 +07:00
|
|
|
|
|
|
|
|
// 404 handler
|
|
|
|
|
app.use((_req: Request, res: Response) => {
|
|
|
|
|
res.status(404).json({
|
|
|
|
|
error: "NOT_FOUND",
|
|
|
|
|
message: "Endpoint not found",
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Error handler (must be last)
|
|
|
|
|
app.use(errorHandler);
|
|
|
|
|
|
|
|
|
|
return app;
|
|
|
|
|
}
|