diff --git a/code/utils/deploy-pokedex.js b/code/utils/deploy-pokedex.js index 442e4dd..97c4934 100644 --- a/code/utils/deploy-pokedex.js +++ b/code/utils/deploy-pokedex.js @@ -120,26 +120,39 @@ function expandTilde(filepath) { } /** - * Create modified docker-compose.yml with custom ports - * @param {number} port - HTTP port to map to container - * @param {number|null} sslPort - HTTPS port to map to container (optional) + * Create modified docker-compose.production.yml with custom ports + * @param {number} port - HTTP port to map to frontend container + * @param {number|null} sslPort - HTTPS port to map to frontend container (optional) + * @param {number} backendPort - Port to map to backend container * @returns {string} Modified docker-compose content */ -function createModifiedDockerCompose(port, sslPort) { - const originalPath = path.join(SOURCE_DIR, 'docker-compose.yml'); +function createModifiedDockerCompose(port, sslPort, backendPort) { + const originalPath = path.join(SOURCE_DIR, 'docker-compose.production.yml'); let content = fs.readFileSync(originalPath, 'utf8'); - // Replace HTTP port mapping (handle both single and double quotes) - content = content.replace(/- ['"](\d+):80['"]/, `- '${port}:80'`); + // Replace frontend HTTP port mapping + content = content.replace( + /(frontend:[\s\S]*?ports:[\s\S]*?- ['"])(\d+)(:80['"])/, + `$1${port}$3` + ); - // Replace HTTPS port mapping if SSL port provided + // Replace frontend HTTPS port mapping if SSL port provided if (sslPort !== null) { - content = content.replace(/- ['"](\d+):443['"]/, `- '${sslPort}:443'`); + content = content.replace( + /(frontend:[\s\S]*?ports:[\s\S]*?- ['"])(\d+)(:443['"])/, + `$1${sslPort}$3` + ); } else { - // Remove HTTPS port mapping if no SSL port specified - content = content.replace(/\s*- ['"](\d+):443['"]/g, ''); + // Remove HTTPS port mapping line if no SSL port specified + content = content.replace(/\s*- ['"](\d+):443['"]\n?/g, ''); } + // Replace backend port mapping + content = content.replace( + /(backend:[\s\S]*?ports:[\s\S]*?- ['"])(\d+)(:3000['"])/, + `$1${backendPort}$3` + ); + return content; }