33 lines
803 B
JavaScript
33 lines
803 B
JavaScript
const express = require("express");
|
|
const path = require("path");
|
|
const fs = require("fs");
|
|
const app = express();
|
|
const PORT = 3000;
|
|
const DOMAIN_FILE = path.join(__dirname, "domain.txt");
|
|
|
|
function readWsDomain() {
|
|
try {
|
|
const val = fs.readFileSync(DOMAIN_FILE, "utf8").trim();
|
|
if (val) return val;
|
|
} catch (err) {
|
|
if (err.code !== "ENOENT") {
|
|
console.warn("Failed to read domain.txt:", err.message);
|
|
}
|
|
}
|
|
return process.env.WS_DOMAIN || "localhost:8080";
|
|
}
|
|
|
|
app.use(express.static("public"));
|
|
|
|
app.get("/ws-domain", (_req, res) => {
|
|
res.json({ domain: readWsDomain() });
|
|
});
|
|
|
|
app.get("/", (req, res) => {
|
|
res.sendFile(path.join(__dirname, "public", "index.html"));
|
|
});
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`Client server running at http://localhost:${PORT}`);
|
|
});
|