feat(gtm-architect): Integrate GTM Architect app with Python backend, DB persistence, and Docker stack

This commit is contained in:
2025-12-31 12:38:28 +00:00
parent aa9ae07c13
commit 682b736e01
12 changed files with 830 additions and 1070 deletions

View File

@@ -7,6 +7,7 @@ const path = require('path');
const app = express();
const PORT = 3002;
const VERSION = "1.1.0-DEBUG (Timeout 600s)";
// Middleware
app.use(cors());
@@ -27,14 +28,32 @@ const runPythonScript = (args, res) => {
pythonProcess.stderr.on('data', (data) => { pythonError += data.toString(); });
pythonProcess.on('close', (code) => {
console.log(`[${new Date().toISOString()}] Python process exited with code ${code}`);
if (pythonOutput.length > 0) {
console.log(`[${new Date().toISOString()}] Stdout (first 500 chars): ${pythonOutput.substring(0, 500)}...`);
} else {
console.log(`[${new Date().toISOString()}] Stdout is empty.`);
}
if (pythonError.length > 0) {
console.log(`[${new Date().toISOString()}] Stderr (first 500 chars): ${pythonError.substring(0, 500)}...`);
}
if (code !== 0) {
console.error(`Python error (Code ${code}): ${pythonError}`);
return res.status(500).json({ error: 'Backend error', details: pythonError });
return res.status(500).json({ error: 'Backend error', details: pythonError, version: VERSION });
}
try {
res.json(JSON.parse(pythonOutput));
res.header('X-Server-Timeout', '600000');
const responseData = JSON.parse(pythonOutput);
// Add version info to the response if it's an object
if (typeof responseData === 'object' && responseData !== null) {
responseData._backend_version = VERSION;
}
res.json(responseData);
} catch (e) {
res.status(500).json({ error: 'Invalid JSON', raw: pythonOutput });
console.error(`JSON Parse Error: ${e.message}`);
console.error(`Raw Output was: ${pythonOutput}`);
res.status(500).json({ error: 'Invalid JSON', raw: pythonOutput, details: e.message, version: VERSION });
}
});
};
@@ -104,7 +123,12 @@ const initializeDatabase = () => {
proc.on('close', (code) => console.log(`[${new Date().toISOString()}] DB init finished (Code ${code})`));
};
app.listen(PORT, () => {
console.log(`B2B Marketing Assistant API Bridge running on port ${PORT}`);
const server = app.listen(PORT, () => {
console.log(`B2B Marketing Assistant API Bridge running on port ${PORT} (Version: ${VERSION})`);
initializeDatabase();
});
// Set timeout to 10 minutes (600s) to handle long AI generation steps
server.setTimeout(600000);
server.keepAliveTimeout = 610000;
server.headersTimeout = 620000;