From 4c07fd5b7346150d0ea0205e29f6345971fcf6f6 Mon Sep 17 00:00:00 2001 From: numex-admin Date: Wed, 9 Sep 2026 22:40:20 +0000 Subject: [PATCH] =?UTF-8?q?Numex=20yay=C4=B1n:=20server.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 server.js diff --git a/server.js b/server.js new file mode 100644 index 0000000..7ea31ea --- /dev/null +++ b/server.js @@ -0,0 +1,47 @@ +/** + * Stüdyo Teleprompter — Express sunucusu + * Dizindeki public/ klasörünü servis eder, otomatik boş port seçer (3000+). + */ +const path = require("path"); +const http = require("http"); +const express = require("express"); + +const app = express(); +const PUBLIC_DIR = path.join(__dirname, "public"); + +// Statik dosyalar +app.use(express.static(PUBLIC_DIR)); + +// Kök isteği index.html'e yönlendir +app.get("/", (req, res) => { + res.sendFile(path.join(PUBLIC_DIR, "index.html")); +}); + +// 3000'den başlayıp boş olan ilk porta bağlanmayı dener +function listenAnywhere(port) { + const server = http.createServer(app); + return new Promise((resolve) => { + const attempt = (p) => { + const trial = server.listen(p); + trial.once("listening", () => resolve(server.address().port)); + trial.once("error", (err) => { + if (err.code === "EADDRINUSE") { + attempt(p + 1); + } else { + console.error("Sunucu hatası:", err); + process.exit(1); + } + }); + }; + attempt(port); + }); +} + +listenAnywhere(process.env.PORT ? parseInt(process.env.PORT, 10) : 3000) + .then((port) => { + console.log("=============================================="); + console.log(" 🎥 Stüdyo Teleprompter çalışıyor"); + console.log(` 📍 http://localhost:${port}`); + console.log(" 🛑 Durdurmak için Ctrl+C"); + console.log("=============================================="); + });