29 lines
984 B
TypeScript
29 lines
984 B
TypeScript
import type { APIRoute } from 'astro';
|
|
import fs from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
|
|
export const prerender = false;
|
|
|
|
const DATA_DIR = process.env.DATA_DIR || path.join(process.cwd(), 'app', 'data');
|
|
|
|
export const POST: APIRoute = async () => {
|
|
try {
|
|
const draftPath = path.join(DATA_DIR, 'site.config.draft.json');
|
|
const livePath = path.join(DATA_DIR, 'site.config.json');
|
|
|
|
// Prüfe ob ein Entwurf existiert
|
|
try {
|
|
await fs.access(draftPath);
|
|
} catch {
|
|
return new Response(JSON.stringify({ error: 'Kein gespeicherter Entwurf vorhanden' }), { status: 404 });
|
|
}
|
|
|
|
// Atomares Kopieren des Entwurfs auf die Live-Konfiguration
|
|
await fs.copyFile(draftPath, livePath);
|
|
|
|
return new Response(JSON.stringify({ success: true, message: 'Website erfolgreich veröffentlicht!' }), { status: 200 });
|
|
} catch (error) {
|
|
return new Response(JSON.stringify({ error: 'Fehler beim Veröffentlichen' }), { status: 500 });
|
|
}
|
|
};
|