"feat: Added debug server and related components for improved development experience"

This commit is contained in:
2025-05-23 07:24:51 +02:00
parent d457a8d86b
commit 9f6219832c
189 changed files with 35730 additions and 133 deletions

179
frontend/update-package.js Normal file
View File

@@ -0,0 +1,179 @@
#!/usr/bin/env node
/**
* Hilfsskript zur Aktualisierung der OAuth-Konfiguration im MYP-Frontend
*
* Dieses Skript wird automatisch beim Build ausgeführt, um sicherzustellen,
* dass die OAuth-Konfiguration korrekt ist.
*/
const fs = require('fs');
const path = require('path');
// Pfad zur OAuth-Konfiguration und Routes
const callbackRoutePath = path.join(__dirname, 'src/app/auth/login/callback/route.ts');
const loginRoutePath = path.join(__dirname, 'src/app/auth/login/route.ts');
const oauthConfigPath = path.join(__dirname, 'src/server/auth/oauth.ts');
// Aktualisiere die OAuth-Konfiguration
try {
// 1. Prüfe, ob wir die USED_CALLBACK_URL exportieren müssen
let oauthContent = fs.readFileSync(oauthConfigPath, 'utf8');
if (!oauthContent.includes('export const USED_CALLBACK_URL')) {
console.log('✅ Aktualisiere OAuth-Konfiguration...');
// Füge die USED_CALLBACK_URL-Export hinzu
oauthContent = oauthContent.replace(
'// Erstelle GitHub OAuth-Client mit expliziter Redirect-URI',
'// Berechne die Callback-URL\nexport const USED_CALLBACK_URL = getCallbackUrl();\n\n// Erstelle GitHub OAuth-Client mit expliziter Redirect-URI'
);
// Schreibe die aktualisierte Datei
fs.writeFileSync(oauthConfigPath, oauthContent, 'utf8');
console.log('✅ OAuth-Konfiguration erfolgreich aktualisiert.');
} else {
console.log(' OAuth-Konfiguration ist bereits aktuell.');
}
} catch (error) {
console.error('❌ Fehler beim Aktualisieren der OAuth-Konfiguration:', error);
}
// Aktualisiere die OAuth-Callback-Route
try {
let callbackContent = fs.readFileSync(callbackRoutePath, 'utf8');
// Prüfe, ob Änderungen nötig sind
const needsUpdate =
callbackContent.includes('await github.validateAuthorizationCode(code, OAUTH_CALLBACK_URL)') ||
!callbackContent.includes('USED_CALLBACK_URL');
if (needsUpdate) {
console.log('✅ Aktualisiere OAuth-Callback-Route...');
// 1. Aktualisiere den Import
if (!callbackContent.includes('USED_CALLBACK_URL')) {
callbackContent = callbackContent.replace(
'import { type GitHubUserResult, github, isValidCallbackHost } from "@/server/auth/oauth";',
'import { type GitHubUserResult, github, isValidCallbackHost, USED_CALLBACK_URL } from "@/server/auth/oauth";'
);
// Entferne den OAUTH_CALLBACK_URL-Import, wenn er nicht mehr benötigt wird
if (callbackContent.includes('OAUTH_CALLBACK_URL')) {
callbackContent = callbackContent.replace(
', OAUTH_CALLBACK_URL } from "@/utils/api-config"',
' } from "@/utils/api-config"'
);
}
}
// 2. Korrigiere die validateAuthorizationCode-Funktion
if (callbackContent.includes('await github.validateAuthorizationCode(code, OAUTH_CALLBACK_URL)')) {
callbackContent = callbackContent.replace(
'await github.validateAuthorizationCode(code, OAUTH_CALLBACK_URL)',
'await github.validateAuthorizationCode(code)'
);
}
// 3. Aktualisiere die Logging-Nachricht
if (callbackContent.includes('console.log(`GitHub OAuth Token-Validierung mit Callback-URL: ${OAUTH_CALLBACK_URL}`)')) {
callbackContent = callbackContent.replace(
'console.log(`GitHub OAuth Token-Validierung mit Callback-URL: ${OAUTH_CALLBACK_URL}`)',
'console.log(`GitHub OAuth Token-Validierung erfolgreich, verwendete Callback-URL: ${USED_CALLBACK_URL}`)'
);
} else if (callbackContent.includes('console.log("GitHub OAuth Token-Validierung erfolgreich")')) {
callbackContent = callbackContent.replace(
'console.log("GitHub OAuth Token-Validierung erfolgreich")',
'console.log(`GitHub OAuth Token-Validierung erfolgreich, verwendete Callback-URL: ${USED_CALLBACK_URL}`)'
);
}
// Schreibe die aktualisierte Datei
fs.writeFileSync(callbackRoutePath, callbackContent, 'utf8');
console.log('✅ OAuth-Callback-Route erfolgreich aktualisiert.');
} else {
console.log(' OAuth-Callback-Route ist bereits aktuell.');
}
} catch (error) {
console.error('❌ Fehler beim Aktualisieren der OAuth-Callback-Route:', error);
}
// Package.json aktualisieren, um das Skript vor dem Build auszuführen
try {
const packageJsonPath = path.join(__dirname, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
// Prüfe, ob das Skript bereits in den Build-Prozess integriert ist
if (packageJson.scripts.build === 'next build') {
console.log('✅ Aktualisiere package.json...');
// Füge das Skript zum Build-Prozess hinzu
packageJson.scripts.build = 'node update-package.js && next build';
// Schreibe die aktualisierte package.json
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
console.log('✅ package.json erfolgreich aktualisiert.');
} else {
console.log(' package.json ist bereits aktualisiert.');
}
} catch (error) {
console.error('❌ Fehler beim Aktualisieren der package.json:', error);
}
// Aktualisiere die Login-Route
try {
let loginContent = fs.readFileSync(loginRoutePath, 'utf8');
// Prüfe, ob Änderungen nötig sind
const loginNeedsUpdate =
loginContent.includes('redirectURI: OAUTH_CALLBACK_URL') ||
!loginContent.includes('USED_CALLBACK_URL');
if (loginNeedsUpdate) {
console.log('✅ Aktualisiere OAuth-Login-Route...');
// 1. Aktualisiere den Import
if (!loginContent.includes('USED_CALLBACK_URL')) {
if (loginContent.includes('import { github } from "@/server/auth/oauth";')) {
loginContent = loginContent.replace(
'import { github } from "@/server/auth/oauth";',
'import { github, USED_CALLBACK_URL } from "@/server/auth/oauth";'
);
}
// Entferne den OAUTH_CALLBACK_URL-Import
if (loginContent.includes('import { OAUTH_CALLBACK_URL } from "@/utils/api-config";')) {
loginContent = loginContent.replace(
'import { OAUTH_CALLBACK_URL } from "@/utils/api-config";',
''
);
}
}
// 2. Korrigiere die createAuthorizationURL-Funktion
if (loginContent.includes('redirectURI: OAUTH_CALLBACK_URL')) {
loginContent = loginContent.replace(
/const url = await github\.createAuthorizationURL\(state, \{\s*scopes: \["user"\],\s*redirectURI: OAUTH_CALLBACK_URL,\s*\}\);/s,
'const url = await github.createAuthorizationURL(state, {\n\t\tscopes: ["user"],\n\t});'
);
}
// 3. Aktualisiere die Logging-Nachricht
if (loginContent.includes('console.log(`Verwendete Callback-URL: ${OAUTH_CALLBACK_URL}`')) {
loginContent = loginContent.replace(
'console.log(`Verwendete Callback-URL: ${OAUTH_CALLBACK_URL}`',
'console.log(`Verwendete Callback-URL: ${USED_CALLBACK_URL}`'
);
}
// Schreibe die aktualisierte Datei
fs.writeFileSync(loginRoutePath, loginContent, 'utf8');
console.log('✅ OAuth-Login-Route erfolgreich aktualisiert.');
} else {
console.log(' OAuth-Login-Route ist bereits aktuell.');
}
} catch (error) {
console.error('❌ Fehler beim Aktualisieren der OAuth-Login-Route:', error);
}
console.log('✅ OAuth-Konfiguration wurde erfolgreich vorbereitet.');