Fix jwt-token

This commit is contained in:
2025-08-19 20:26:41 +02:00
parent 6fd3c0fe3f
commit 7f06cd6dbc

View File

@@ -3,28 +3,24 @@ const path = require('path');
class ApiDebugLogger {
constructor() {
this.logFile = path.join(__dirname, '..', 'logs', 'api_debug.log');
// Use /tmp directory which has universal write permissions in containers
this.logFile = '/tmp/api_debug.log';
this.enabled = process.env.NODE_ENV === 'development' || process.env.API_DEBUG === 'true';
this.fileLoggingEnabled = false;
// Debug logging setup
if (this.enabled) {
console.log(`🐛 ApiDebugLogger: Enabled (NODE_ENV=${process.env.NODE_ENV}, API_DEBUG=${process.env.API_DEBUG})`);
console.log(`🐛 ApiDebugLogger: Log file path: ${this.logFile}`);
// Ensure the logs directory exists
// Try to enable file logging
try {
const logsDir = path.dirname(this.logFile);
if (!fs.existsSync(logsDir)) {
fs.mkdirSync(logsDir, { recursive: true });
console.log(`🐛 ApiDebugLogger: Created logs directory at ${logsDir}`);
}
if (!fs.existsSync(this.logFile)) {
fs.writeFileSync(this.logFile, `# API Debug Log Started at ${new Date().toISOString()}\n`);
console.log(`🐛 ApiDebugLogger: Created log file at ${this.logFile}`);
}
fs.writeFileSync(this.logFile, `# API Debug Log Started at ${new Date().toISOString()}\n`);
this.fileLoggingEnabled = true;
console.log(`🐛 ApiDebugLogger: File logging enabled at ${this.logFile}`);
} catch (error) {
console.error(` ApiDebugLogger: Failed to create log file: ${error}`);
console.warn(`⚠️ ApiDebugLogger: File logging disabled - using console only. Error: ${error.message}`);
this.fileLoggingEnabled = false;
}
} else {
console.log(`🐛 ApiDebugLogger: Disabled (NODE_ENV=${process.env.NODE_ENV}, API_DEBUG=${process.env.API_DEBUG})`);
@@ -53,11 +49,17 @@ class ApiDebugLogger {
`HEADERS:${JSON.stringify(sanitizedHeaders)}`
].join(' ');
try {
fs.appendFileSync(this.logFile, logEntry + '\n');
console.log(`🐛 API Log: ${method.toUpperCase()} ${url} - ${statusCode}`);
} catch (error) {
console.error('❌ Failed to write to API debug log:', error);
// Always log to console
console.log(`🐛 API Log: ${method.toUpperCase()} ${url} - ${statusCode}`);
// Try to log to file if enabled
if (this.fileLoggingEnabled) {
try {
fs.appendFileSync(this.logFile, logEntry + '\n');
} catch (error) {
console.warn(`⚠️ File logging failed, disabling: ${error.message}`);
this.fileLoggingEnabled = false;
}
}
}
@@ -101,11 +103,17 @@ class ApiDebugLogger {
const timestamp = new Date().toISOString();
const logEntry = `[${timestamp}] INCOMING ${req.method} ${req.url} - BODY:${JSON.stringify(this.sanitizeData(req.body))} - HEADERS:${JSON.stringify(this.sanitizeHeaders(req.headers))}`;
try {
fs.appendFileSync(this.logFile, logEntry + '\n');
console.log(`🐛 API Request: ${req.method} ${req.url}`);
} catch (error) {
console.error('❌ Failed to write request to API debug log:', error);
// Always log to console
console.log(`🐛 API Request: ${req.method} ${req.url}`);
// Try to log to file if enabled
if (this.fileLoggingEnabled) {
try {
fs.appendFileSync(this.logFile, logEntry + '\n');
} catch (error) {
console.warn(`⚠️ File logging failed, disabling: ${error.message}`);
this.fileLoggingEnabled = false;
}
}
}