Node.js/Express-Server als Ersatz fuer den Cloudflare gate-worker.js
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
/* =====================================================================
|
||||
index.js — Haupteinstiegspunkt für DogFather Universe. Liefert die statische Website aus
|
||||
(../ ist der Ordner mit allen .html-Dateien) plus die Zugangsschranke (gate.js), 1:1 wie
|
||||
vorher der Cloudflare Worker (gate-worker.js).
|
||||
===================================================================== */
|
||||
|
||||
import "dotenv/config";
|
||||
import express from "express";
|
||||
import cookieParser from "cookie-parser";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { gateMiddleware } from "./gate.js";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const SITE_DIR = join(__dirname, "..");
|
||||
const PORT = Number(process.env.PORT || 4100);
|
||||
|
||||
const app = express();
|
||||
app.set("trust proxy", 1);
|
||||
|
||||
app.use(cookieParser());
|
||||
app.use(express.json({ limit: "1mb" }));
|
||||
app.use(gateMiddleware);
|
||||
|
||||
app.use(express.static(SITE_DIR, { index: "index.html" }));
|
||||
|
||||
app.use((req, res) => {
|
||||
res.status(404).sendFile(join(SITE_DIR, "404.html"), (err) => {
|
||||
if (err) res.status(404).send("Nicht gefunden.");
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(PORT, "127.0.0.1", () => {
|
||||
console.log(`DogFather Universe – Server läuft auf http://127.0.0.1:${PORT}`);
|
||||
});
|
||||
Reference in New Issue
Block a user