repiped/server.js
2025-04-30 19:01:10 +02:00

35 lines
976 B
JavaScript

const express = require("express");
const app = express();
const enableWs = require("express-ws");
const fs = require("fs");
const path = require("path");
require("dotenv").config();
enableWs(app);
const createCacheManager = require("./middleware/cacheManager");
app.use(createCacheManager());
const videoHostDir = path.join(__dirname, "videohost");
if (!fs.existsSync(videoHostDir)) {
fs.mkdirSync(videoHostDir);
console.log("Created videohost directory");
}
const routesPath = path.join(__dirname, "routes");
fs.readdirSync(routesPath).forEach((file) => {
if (file.endsWith(".js")) {
const routeHandler = require(path.join(routesPath, file));
routeHandler(app);
console.log(`Loaded route handler: ${file}`);
}
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
process.on("SIGINT", () => {
console.log("Shutting down repiped...");
process.exit(0);
});
});