Fix jwt-token
This commit is contained in:
@@ -3,28 +3,24 @@ const path = require('path');
|
|||||||
|
|
||||||
class ApiDebugLogger {
|
class ApiDebugLogger {
|
||||||
constructor() {
|
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.enabled = process.env.NODE_ENV === 'development' || process.env.API_DEBUG === 'true';
|
||||||
|
this.fileLoggingEnabled = false;
|
||||||
|
|
||||||
// Debug logging setup
|
// Debug logging setup
|
||||||
if (this.enabled) {
|
if (this.enabled) {
|
||||||
console.log(`🐛 ApiDebugLogger: Enabled (NODE_ENV=${process.env.NODE_ENV}, API_DEBUG=${process.env.API_DEBUG})`);
|
console.log(`🐛 ApiDebugLogger: Enabled (NODE_ENV=${process.env.NODE_ENV}, API_DEBUG=${process.env.API_DEBUG})`);
|
||||||
console.log(`🐛 ApiDebugLogger: Log file path: ${this.logFile}`);
|
console.log(`🐛 ApiDebugLogger: Log file path: ${this.logFile}`);
|
||||||
|
|
||||||
// Ensure the logs directory exists
|
// Try to enable file logging
|
||||||
try {
|
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`);
|
fs.writeFileSync(this.logFile, `# API Debug Log Started at ${new Date().toISOString()}\n`);
|
||||||
console.log(`🐛 ApiDebugLogger: Created log file at ${this.logFile}`);
|
this.fileLoggingEnabled = true;
|
||||||
}
|
console.log(`🐛 ApiDebugLogger: File logging enabled at ${this.logFile}`);
|
||||||
} catch (error) {
|
} 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 {
|
} else {
|
||||||
console.log(`🐛 ApiDebugLogger: Disabled (NODE_ENV=${process.env.NODE_ENV}, API_DEBUG=${process.env.API_DEBUG})`);
|
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)}`
|
`HEADERS:${JSON.stringify(sanitizedHeaders)}`
|
||||||
].join(' ');
|
].join(' ');
|
||||||
|
|
||||||
|
// Always log to console
|
||||||
|
console.log(`🐛 API Log: ${method.toUpperCase()} ${url} - ${statusCode}`);
|
||||||
|
|
||||||
|
// Try to log to file if enabled
|
||||||
|
if (this.fileLoggingEnabled) {
|
||||||
try {
|
try {
|
||||||
fs.appendFileSync(this.logFile, logEntry + '\n');
|
fs.appendFileSync(this.logFile, logEntry + '\n');
|
||||||
console.log(`🐛 API Log: ${method.toUpperCase()} ${url} - ${statusCode}`);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('❌ Failed to write to API debug log:', error);
|
console.warn(`⚠️ File logging failed, disabling: ${error.message}`);
|
||||||
|
this.fileLoggingEnabled = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,11 +103,17 @@ class ApiDebugLogger {
|
|||||||
const timestamp = new Date().toISOString();
|
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))}`;
|
const logEntry = `[${timestamp}] INCOMING ${req.method} ${req.url} - BODY:${JSON.stringify(this.sanitizeData(req.body))} - HEADERS:${JSON.stringify(this.sanitizeHeaders(req.headers))}`;
|
||||||
|
|
||||||
|
// Always log to console
|
||||||
|
console.log(`🐛 API Request: ${req.method} ${req.url}`);
|
||||||
|
|
||||||
|
// Try to log to file if enabled
|
||||||
|
if (this.fileLoggingEnabled) {
|
||||||
try {
|
try {
|
||||||
fs.appendFileSync(this.logFile, logEntry + '\n');
|
fs.appendFileSync(this.logFile, logEntry + '\n');
|
||||||
console.log(`🐛 API Request: ${req.method} ${req.url}`);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('❌ Failed to write request to API debug log:', error);
|
console.warn(`⚠️ File logging failed, disabling: ${error.message}`);
|
||||||
|
this.fileLoggingEnabled = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user