feat(waas): add catch-all route, page manager and draft-publish pipeline
This commit is contained in:
28
src/pages/api/editor/publish.ts
Normal file
28
src/pages/api/editor/publish.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
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 });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user