🔧 Update docker-compose modification logic to include backend port mapping and refine frontend port handling
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user