config.js für Namen und Farbe Variable eingebaut

This commit is contained in:
Honey committed 2026-02-12 14:40:14 +01:00
1 parent 22779120b3
commit 81d85a0d68
4 files changed
+129 -34

No files matched your search

+29 -24
View File
@@ -2,6 +2,7 @@ import express from "express";
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
import { CONFIG, DISCORD_WEBHOOK_URL, PUBLIC_BASE_URL, PORT } from "./config.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
@@ -37,25 +38,6 @@ app.use(express.static(path.join(__dirname, "public"), {
const stateFile = path.join(__dirname, "state.json");
// --------------------
// Konfiguration
// --------------------
const CONFIG = {
A: {
name: "Marc",
color: 0x2ecc71,
icon: "a.png"
},
B: {
name: "Laila",
color: 0xe74c3c,
icon: "b.png"
}
};
const PUBLIC_BASE_URL = process.env.PUBLIC_BASE_URL || "http://localhost:3000";
const DISCORD_WEBHOOK_URL = process.env.DISCORD_WEBHOOK_URL || "https://discord.com/api/webhooks/1450872860607381515/zRbiXOykKPUfLJ_H87wD2OxQJPLdro6yQzU2T48Pg4fxSNaXEqBFgxdHGTiIDmmKGHIF";
// --------------------
// State Handling - MIT PERSISTENT lastReason
// --------------------
@@ -107,12 +89,12 @@ async function sendDiscordEmbed(previousKey, currentKey, reason) {
const fields = [
{
name: "Payed",
name: "Paid",
value: previous.name,
inline: true
},
{
name: "Nows turn",
name: "Now's turn",
value: current.name,
inline: true
}
@@ -128,8 +110,8 @@ async function sendDiscordEmbed(previousKey, currentKey, reason) {
const embed = {
title: "💸 Pay-Switch",
description: `*${current.name}** turn`,
color: current.color,
description: `**${current.name}**'s turn`,
color: current.colorDiscord, // ← Verwendet colorDiscord aus config.js
thumbnail: {
url: `${PUBLIC_BASE_URL}/img/${current.icon}`
},
@@ -155,6 +137,26 @@ async function sendDiscordEmbed(previousKey, currentKey, reason) {
// API Routes
// --------------------
// Config API endpoint - sendet Config an Frontend
app.get("/config", (req, res) => {
// Nur relevante Daten fürs Frontend senden
const frontendConfig = {
A: {
name: CONFIG.A.name,
colorHex: CONFIG.A.colorHex,
icon: CONFIG.A.icon,
background: CONFIG.A.background
},
B: {
name: CONFIG.B.name,
colorHex: CONFIG.B.colorHex,
icon: CONFIG.B.icon,
background: CONFIG.B.background
}
};
res.json(frontendConfig);
});
app.get("/status", (req, res) => {
const state = getState();
res.json(state);
@@ -221,7 +223,6 @@ app.use((err, req, res, next) => {
// --------------------
// Start
// --------------------
const PORT = process.env.PORT || 3000;
app.listen(PORT, "0.0.0.0", () => {
console.log(`\n✅ WhoPays läuft auf http://0.0.0.0:${PORT}\n`);
console.log(`📁 Static files directory: ${path.join(__dirname, "public")}`);
@@ -233,6 +234,10 @@ app.listen(PORT, "0.0.0.0", () => {
console.log(` 👤 Wer zahlt: ${CONFIG[initialState.current].name}`);
console.log(` 📝 Letzter Grund: ${initialState.lastReason || 'Keiner gespeichert'}`);
console.log(`\n👥 Konfigurierte Personen:`);
console.log(` A: ${CONFIG.A.name} (${CONFIG.A.colorHex})`);
console.log(` B: ${CONFIG.B.name} (${CONFIG.B.colorHex})`);
// Verify critical files exist
const criticalFiles = [
'public/index.html',