UNPKG

navy

Version:

Quick and powerful development environments using Docker and Docker Compose

76 lines (63 loc) 2.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _lodash = require("lodash"); var _serviceHost = require("../util/service-host"); var _https = require("../util/https"); const getServiceHTTPProxyConfig = (serviceName, navyFile) => { if (navyFile && navyFile.httpProxy && navyFile.httpProxy[serviceName]) { return navyFile.httpProxy[serviceName]; } return null; }; const serviceGetAutoProxyPortOr80 = (service, navyFile) => { const autoPorts = navyFile && Array.isArray(navyFile.httpProxyAutoPorts) && navyFile.httpProxyAutoPorts || ['80']; return service.ports && (0, _lodash.find)(autoPorts, autoPort => { const autoPortString = autoPort.toString(); return (0, _lodash.find)(service.ports, portDefinition => { // In older versions of Docker Compose `ports` could just be an array of string/number, // but it's changed to e.g. {target: "80"} const port = typeof portDefinition === 'object' && 'target' in portDefinition ? portDefinition.target : portDefinition; const portString = port.toString(); return portString === autoPortString || portString.startsWith(`${autoPortString}:`) || portString.startsWith(`${autoPortString}/`); }); }); }; var _default = navy => async (config, state) => { const navyFile = await navy.getNavyFile(); const services = {}; const externalIP = await navy.externalIP(); await Promise.all(Object.keys(config.services).map(async serviceName => { const service = config.services[serviceName]; let proxyConfig = getServiceHTTPProxyConfig(serviceName, navyFile); // proxy port 80 even without service config, or a different port with config httpProxyAutoPorts if (!proxyConfig) { const autoPort = serviceGetAutoProxyPortOr80(service, navyFile); if (autoPort) { proxyConfig = { port: parseInt(autoPort) }; } } if (proxyConfig) { const hostName = await (0, _serviceHost.createHostForService)(serviceName, navy.normalisedName, externalIP); if (proxyConfig.enableHttps) await (0, _https.createCert)({ hostName }); return services[serviceName] = { ...service, environment: { 'VIRTUAL_HOST': hostName, 'VIRTUAL_PORT': proxyConfig.port, ...service.environment } }; } return services[serviceName] = service; })); return { ...config, services }; }; exports.default = _default; module.exports = exports.default;