Some tyhigns.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const express = require("express");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const isDev = process.env.NODE_ENV !== "production";
|
||||
let livereload, connectLivereload;
|
||||
if (isDev) {
|
||||
@@ -8,6 +9,19 @@ if (isDev) {
|
||||
}
|
||||
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";
|
||||
}
|
||||
|
||||
if (isDev) {
|
||||
const liveReloadServer = livereload.createServer();
|
||||
@@ -17,6 +31,10 @@ if (isDev) {
|
||||
|
||||
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"));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user