Ajout interface admin déployable sur serveur

- API routes pour gestion clients (CRUD complet)
- Système de stockage JSON persistant (data/clients.json)
- Configuration Next.js serveur (next.config.server.js)
- Script de build pour déploiement (scripts/build-server.sh)
- Documentation complète de déploiement (ADMIN_DEPLOY.md)

Fonctionnalités admin:
- Création/modification/suppression de clients
- Génération automatique de tokens uniques
- QR codes pour configuration clients
- Authentification par mot de passe
- Backend Node.js avec API REST

Déploiement prévu: marama.syoul.fr
This commit is contained in:
2025-11-23 10:57:01 +01:00
parent 43b733b439
commit ea2d620c7a
8 changed files with 1003 additions and 0 deletions

View File

@ -0,0 +1,55 @@
import { NextRequest, NextResponse } from "next/server";
import { readFile } from "fs/promises";
import { existsSync } from "fs";
import path from "path";
import { Client } from "@/lib/types/client";
const DATA_DIR = path.join(process.cwd(), "data");
const CLIENTS_FILE = path.join(DATA_DIR, "clients.json");
async function loadClients(): Promise<Client[]> {
try {
if (!existsSync(CLIENTS_FILE)) {
return [];
}
const data = await readFile(CLIENTS_FILE, "utf-8");
return JSON.parse(data);
} catch (error) {
console.error("Erreur lecture clients:", error);
return [];
}
}
// GET - Récupérer les données d'un client par son token
export async function GET(
request: NextRequest,
{ params }: { params: { token: string } }
) {
try {
const clients = await loadClients();
const client = clients.find(c => c.token === params.token);
if (!client) {
return NextResponse.json(
{ error: "Client non trouvé" },
{ status: 404 }
);
}
// Retourner uniquement les données nécessaires (pas le token ni l'ID)
return NextResponse.json({
bungalowNumber: client.bungalowNumber,
wifiName: client.wifiName,
wifiPassword: client.wifiPassword,
gerantMessage: client.gerantMessage,
});
} catch (error) {
console.error("Erreur GET client par token:", error);
return NextResponse.json(
{ error: "Erreur serveur" },
{ status: 500 }
);
}
}