"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.clickhouseService = exports.redisClient = void 0;
const dotenv_1 = __importDefault(require("dotenv"));
dotenv_1.default.config();
const express_1 = __importDefault(require("express"));
const http_1 = __importDefault(require("http")); // For controlling keepAliveTimeout
const path_1 = __importDefault(require("path"));
const apiRoutes_1 = __importDefault(require("./routes/apiRoutes"));
const clients_1 = require("./services/clients"); // 导入新的初始化函数和客户端
Object.defineProperty(exports, "redisClient", { enumerable: true, get: function () { return clients_1.redisClient; } });
Object.defineProperty(exports, "clickhouseService", { enumerable: true, get: function () { return clients_1.clickhouseService; } });
const app = (0, express_1.default)();
const port = process.env.PORT || 3000;
// Middleware
app.set("trust proxy", true);
app.use(express_1.default.json());
// API routes
app.use("/api", apiRoutes_1.default);
// Static and SPA routing... (Keep your existing code here)
let publicPath;
let angularAppPath;
if (process.env.NODE_ENV === "production") {
    publicPath = path_1.default.resolve(__dirname, "..", "..", "public");
    angularAppPath = path_1.default.join(publicPath, "app");
}
else {
    publicPath = path_1.default.resolve(__dirname, "..", "public");
    angularAppPath = path_1.default.join(publicPath, "app");
}
console.log(process.env.NODE_ENV);
console.log(`publicPath: ${publicPath}`);
console.log(`angularAppPath: ${angularAppPath}`);
app.use(express_1.default.static(publicPath));
app.use((req, res) => {
    res.sendFile(path_1.default.join(angularAppPath, "index.html"));
});
// Start the server
async function startServer() {
    await (0, clients_1.initializeClients)(); // 先初始化所有客户端
    const server = http_1.default.createServer(app);
    // server.keepAliveTimeout = 61 * 1000;
    // server.headersTimeout = 65 * 1000;
    server.listen(port, () => {
        console.log(`OMS Backend server listening on port ${port}`);
    });
}
startServer();
