fix: 403-Schutz + Selbstheilung fuer geloeschte Preview-Config

- runDeploy schreibt Platzhalter-index.html, wenn das Deploy-Verzeichnis
  keine index.html enthaelt (leergeraeumtes Repo/Fehlbuild) -> nie mehr
  nginx 403 Forbidden, Subdomain bleibt erreichbar.
- deployStatic: Fallback auf Repo-Wurzel bei fehlendem index-Unterordner,
  .git wird nicht mehr mit ausgeliefert.
- Webhook: fehlt .webklar-preview.json im Repo, wird die Hosting-Config aus
  dem Appwrite-Projektstand rekonstruiert, ins Repo zurueckgeschrieben und
  normal deployt (ensureRepoPreviewConfig).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-07-12 18:05:00 +00:00
parent 07ebcc7e62
commit 1b4262b09f
3 changed files with 125 additions and 3 deletions

View File

@@ -231,6 +231,47 @@ async function updatePreviewConfigFile(repoFullName, previewConfig, branch = 'ma
})
}
/**
* Selbstheilung fuer eine geloeschte/fehlende .webklar-preview.json:
* Rekonstruiert die Hosting-Config aus dem in Appwrite gespeicherten
* Projektstand (Subdomain, Typ, Name), schreibt sie ins Repo zurueck und liefert
* sie fuer einen sofortigen Deploy zurueck. Gibt null zurueck, wenn zu dem Repo
* kein gehostetes, aktives Projekt bekannt ist (dann bleibt es Repo-only).
*/
export async function ensureRepoPreviewConfig(repoFullName, branch = 'main') {
if (!repoFullName) return null
const docs = await listDocuments(config.collections.websiteProjects, [
Query.equal('repoFullName', repoFullName),
Query.limit(1),
])
const doc = docs[0]
if (!doc || doc.archived) return null
const type = deriveProjectType(doc)
const hasWebsite = type === 'preview' || type === 'website' || type === 'template'
const subdomain = doc.subdomain || ''
if (!hasWebsite || !subdomain) return null
const previewConfig = {
enabled: true,
type: 'static',
branch,
displayName: doc.projectName || repoFullName.split('/').pop(),
templateName: doc.templateName || config.gitea.templateRepo,
projectType: type,
public: type === 'website',
template: type === 'template',
subdomain,
}
try {
await updatePreviewConfigFile(repoFullName, previewConfig, branch)
} catch (err) {
console.error('[ensureRepoPreviewConfig] .webklar-preview.json zurueckschreiben fehlgeschlagen:', err.message)
}
return previewConfig
}
export async function createProjectFromTemplate({
repoName,
displayName,