chore(gtm): Optimize Docker container with multi-stage build and flat structure
This commit is contained in:
@@ -1,15 +1,31 @@
|
||||
const express = require('express');
|
||||
const { spawn } = require('child_process');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const app = express();
|
||||
const port = 3005; // Port for the GTM Architect service
|
||||
|
||||
app.use(express.json({ limit: '50mb' }));
|
||||
|
||||
// Middleware to serve static files from the React app
|
||||
app.use(express.static('.'));
|
||||
// Determine Environment and Paths
|
||||
const distPath = path.join(__dirname, 'dist');
|
||||
const isProduction = fs.existsSync(distPath);
|
||||
const staticDir = isProduction ? distPath : __dirname;
|
||||
|
||||
console.log(`[Init] Serving static files from: ${staticDir}`);
|
||||
app.use(express.static(staticDir));
|
||||
|
||||
// Determine Python Script Path
|
||||
// In Docker (optimized), script is in same dir. Locally, it might be one level up.
|
||||
let pythonScriptPath = path.join(__dirname, 'gtm_architect_orchestrator.py');
|
||||
if (!fs.existsSync(pythonScriptPath)) {
|
||||
pythonScriptPath = path.join(__dirname, '../gtm_architect_orchestrator.py');
|
||||
}
|
||||
console.log(`[Init] Using Python script at: ${pythonScriptPath}`);
|
||||
|
||||
|
||||
function callPythonScript(mode, data, res) {
|
||||
const pythonProcess = spawn('python3', ['../gtm_architect_orchestrator.py', '--mode', mode]);
|
||||
const pythonProcess = spawn('python3', [pythonScriptPath, '--mode', mode]);
|
||||
|
||||
let pythonData = '';
|
||||
let errorData = '';
|
||||
@@ -53,7 +69,7 @@ app.post('/api/gtm', (req, res) => {
|
||||
|
||||
// Serve the main index.html for any other requests to support client-side routing
|
||||
app.get('*', (req, res) => {
|
||||
res.sendFile(__dirname + '/index.html');
|
||||
res.sendFile(path.join(staticDir, 'index.html'));
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user