2023-02-12 07:40:49 +00:00
|
|
|
import "dotenv/config";
|
2022-07-08 19:17:56 +01:00
|
|
|
|
|
|
|
import express from "express";
|
2024-10-31 22:59:06 +00:00
|
|
|
import cluster from "node:cluster";
|
2023-04-29 12:40:08 +01:00
|
|
|
|
2024-10-20 14:07:42 +01:00
|
|
|
import path from "path";
|
|
|
|
import { fileURLToPath } from "url";
|
2022-07-08 19:17:56 +01:00
|
|
|
|
2024-10-31 22:59:06 +00:00
|
|
|
import { env, isCluster } from "./config.js"
|
2024-10-20 14:07:42 +01:00
|
|
|
import { Red } from "./misc/console-text.js";
|
2024-10-31 22:59:06 +00:00
|
|
|
import { initCluster } from "./misc/cluster.js";
|
2022-07-10 15:04:03 +01:00
|
|
|
|
2024-08-03 16:34:02 +01:00
|
|
|
const app = express();
|
2022-07-08 19:17:56 +01:00
|
|
|
|
2023-05-21 20:13:05 +01:00
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
2023-06-27 14:56:15 +01:00
|
|
|
const __dirname = path.dirname(__filename).slice(0, -4);
|
2023-02-12 07:40:49 +00:00
|
|
|
|
2024-10-20 14:07:42 +01:00
|
|
|
app.disable("x-powered-by");
|
2023-02-12 07:40:49 +00:00
|
|
|
|
2024-08-02 16:32:00 +01:00
|
|
|
if (env.apiURL) {
|
2024-10-20 14:07:42 +01:00
|
|
|
const { runAPI } = await import("./core/api.js");
|
2024-10-31 22:59:06 +00:00
|
|
|
|
2024-11-01 12:16:53 +00:00
|
|
|
if (isCluster) {
|
2024-11-01 13:30:32 +00:00
|
|
|
await initCluster();
|
2024-10-31 22:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
runAPI(express, app, __dirname, cluster.isPrimary);
|
2022-07-08 19:17:56 +01:00
|
|
|
} else {
|
2023-12-02 16:01:58 +00:00
|
|
|
console.log(
|
2024-10-20 14:07:42 +01:00
|
|
|
Red("API_URL env variable is missing, cobalt api can't start.")
|
2023-12-02 16:01:58 +00:00
|
|
|
)
|
2022-08-01 16:48:37 +01:00
|
|
|
}
|