fix: Use absolute path for market_db_manager.py in B2B server.cjs to resolve 'file not found' error
This commit is contained in:
@@ -16,6 +16,7 @@ app.use(bodyParser.json({ limit: '10mb' })); // Erhöhe das Limit für potenziel
|
||||
const PYTHON_EXECUTABLE = 'python3'; // Annahme, dass python3 im PATH des Containers ist
|
||||
// Im Docker-Container liegen server.cjs und das Python-Skript im selben Verzeichnis (/app)
|
||||
const SCRIPT_PATH = path.join(__dirname, 'b2b_marketing_orchestrator.py');
|
||||
const dbScript = '/app/market_db_manager.py'; // Absoluter Pfad zum DB Manager im Container
|
||||
|
||||
|
||||
// Helper-Funktion zum Ausführen des Python-Skripts
|
||||
@@ -166,10 +167,6 @@ app.post('/api/next-step', (req, res) => {
|
||||
|
||||
// --- DATABASE ROUTES ---
|
||||
|
||||
// Initialize DB on startup
|
||||
const dbScript = path.join(__dirname, 'market_db_manager.py');
|
||||
spawn('python3', [dbScript, 'init']);
|
||||
|
||||
app.get('/api/projects', (req, res) => {
|
||||
runPythonScript([dbScript, 'list'], res);
|
||||
});
|
||||
@@ -191,13 +188,6 @@ app.post('/api/save-project', (req, res) => {
|
||||
try {
|
||||
fs.writeFileSync(tempFilePath, JSON.stringify(projectData));
|
||||
runPythonScript([dbScript, 'save', tempFilePath], res);
|
||||
// Clean up temp file
|
||||
if (fs.existsSync(tempFilePath)) {
|
||||
// Note: runPythonScript is async, so we might want to handle deletion there
|
||||
// But since we are passing it to python which reads it, we'll let it be for now
|
||||
// or pass it to runPythonScript cleanup if we had that.
|
||||
// For now, I'll just leave it and let the user manage tmp if needed.
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).json({ error: 'Failed to write project data to disk' });
|
||||
}
|
||||
@@ -212,7 +202,34 @@ app.get('*', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'dist', 'index.html'));
|
||||
});
|
||||
|
||||
// Separate function to initialize the database, called after server starts
|
||||
const initializeDatabase = () => {
|
||||
console.log(`[${new Date().toISOString()}] Initializing B2B database...`);
|
||||
const pythonProcess = spawn(PYTHON_EXECUTABLE, [dbScript, 'init']);
|
||||
|
||||
pythonProcess.stdout.on('data', (data) => {
|
||||
console.log(`[DB Init STDOUT]: ${data.toString().trim()}`);
|
||||
});
|
||||
|
||||
pythonProcess.stderr.on('data', (data) => {
|
||||
console.error(`[DB Init STDERR]: ${data.toString().trim()}`);
|
||||
});
|
||||
|
||||
pythonProcess.on('close', (code) => {
|
||||
if (code === 0) {
|
||||
console.log(`[${new Date().toISOString()}] B2B database initialized successfully.`);
|
||||
} else {
|
||||
console.error(`[${new Date().toISOString()}] B2B database initialization failed with code: ${code}`);
|
||||
}
|
||||
});
|
||||
|
||||
pythonProcess.on('error', (err) => {
|
||||
console.error(`[${new Date().toISOString()}] Failed to spawn Python for DB init:`, err);
|
||||
});
|
||||
};
|
||||
|
||||
// Start des Servers
|
||||
app.listen(PORT, () => {
|
||||
console.log(`B2B Marketing Assistant API Bridge running on http://localhost:${PORT}`);
|
||||
initializeDatabase(); // Initialize DB after server is listening
|
||||
});
|
||||
Reference in New Issue
Block a user