diff --git a/src/dev-server/http-server.ts b/src/dev-server/http-server.ts index ad6bd4e6..fa285b96 100644 --- a/src/dev-server/http-server.ts +++ b/src/dev-server/http-server.ts @@ -14,6 +14,8 @@ import { import { Logger } from '../logger/logger'; import * as proxyMiddleware from 'proxy-middleware'; import { injectDiagnosticsHtml } from '../logger/logger-diagnostics'; +import * as Constants from '../util/constants'; +import { getBooleanPropertyValue } from '../util/helpers'; import { getProjectJson, IonicProject } from '../util/ionic-project'; import { LabAppView, ApiCordovaProject } from './lab'; @@ -51,20 +53,23 @@ export function createHttpServer(config: ServeConfig): express.Application { } function setupProxies(app: express.Application) { - - getProjectJson().then(function(projectConfig: IonicProject) { - for (const proxy of projectConfig.proxies || []) { - let opts: any = url.parse(proxy.proxyUrl); - if (proxy.proxyNoAgent) { - opts.agent = false; + if (getBooleanPropertyValue(Constants.ENV_READ_CONFIG_JSON)) { + getProjectJson().then(function(projectConfig: IonicProject) { + for (const proxy of projectConfig.proxies || []) { + let opts: any = url.parse(proxy.proxyUrl); + if (proxy.proxyNoAgent) { + opts.agent = false; + } + + opts.rejectUnauthorized = !(proxy.rejectUnauthorized === false); + + app.use(proxy.path, proxyMiddleware(opts)); + Logger.info('Proxy added:' + proxy.path + ' => ' + url.format(opts)); } - - opts.rejectUnauthorized = !(proxy.rejectUnauthorized === false); - - app.use(proxy.path, proxyMiddleware(opts)); - Logger.info('Proxy added:' + proxy.path + ' => ' + url.format(opts)); - } - }); + }).catch((err: Error) => { + Logger.error(`Failed to read the projects ionic.config.json file: ${err.message}`); + }); + } } /** @@ -74,7 +79,7 @@ function serveIndex(req: express.Request, res: express.Response) { const config: ServeConfig = req.app.get('serveConfig'); // respond with the index.html file - const indexFileName = path.join(config.wwwDir, 'index.html'); + const indexFileName = path.join(config.wwwDir, process.env[Constants.ENV_VAR_HTML_TO_SERVE]); fs.readFile(indexFileName, (err, indexHtml) => { if (config.useLiveReload) { indexHtml = injectLiveReloadScript(indexHtml, config.host, config.liveReloadPort); diff --git a/src/util/config.ts b/src/util/config.ts index 3ffc8d9c..781223c0 100644 --- a/src/util/config.ts +++ b/src/util/config.ts @@ -75,7 +75,8 @@ export function generateContext(context?: BuildContext): BuildContext { setProcessEnvVar(Constants.ENV_VAR_WWW_DIR, context.wwwDir); Logger.debug(`wwwDir set to ${context.wwwDir}`); - context.wwwIndex = join(context.wwwDir, Constants.WWW_INDEX_FILENAME); + context.wwwIndex = getConfigValue(context, '--wwwIndex', null, Constants.ENV_VAR_HTML_TO_SERVE, Constants.ENV_VAR_HTML_TO_SERVE.toLowerCase(), 'index.html'); + setProcessEnvVar(Constants.ENV_VAR_HTML_TO_SERVE, context.wwwIndex); Logger.debug(`wwwIndex set to ${context.wwwIndex}`); context.buildDir = resolve(context.buildDir || getConfigValue(context, '--buildDir', null, Constants.ENV_VAR_BUILD_DIR, Constants.ENV_VAR_BUILD_DIR.toLowerCase(), join(context.wwwDir, Constants.BUILD_DIR))); @@ -118,6 +119,10 @@ export function generateContext(context?: BuildContext): BuildContext { setProcessEnvVar(Constants.ENV_TS_CONFIG, tsConfigPathValue); Logger.debug(`tsconfig set to ${tsConfigPathValue}`); + const readConfigJson = resolve(getConfigValue(context, '--readConfigJson', null, Constants.ENV_READ_CONFIG_JSON, Constants.ENV_READ_CONFIG_JSON.toLowerCase(), 'true')); + setProcessEnvVar(Constants.ENV_READ_CONFIG_JSON, readConfigJson); + Logger.debug(`readConfigJson set to ${readConfigJson}`); + const appEntryPointPathValue = resolve(getConfigValue(context, '--appEntryPoint', null, Constants.ENV_APP_ENTRY_POINT, Constants.ENV_APP_ENTRY_POINT.toLowerCase(), join(context.srcDir, 'app', 'main.ts'))); setProcessEnvVar(Constants.ENV_APP_ENTRY_POINT, appEntryPointPathValue); Logger.debug(`appEntryPoint set to ${appEntryPointPathValue}`); diff --git a/src/util/constants.ts b/src/util/constants.ts index d3fefab9..3761c37b 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -13,7 +13,6 @@ export const TMP_DIR = '.tmp'; export const WWW_DIR = 'www'; export const NODE_MODULES = 'node_modules'; export const IONIC_ANGULAR = 'ionic-angular'; -export const WWW_INDEX_FILENAME = 'index.html'; export const ENV_VAR_PROD = 'prod'; export const ENV_VAR_DEV = 'dev'; @@ -22,6 +21,7 @@ export const ENV_VAR_ROOT_DIR = 'IONIC_ROOT_DIR'; export const ENV_VAR_SRC_DIR = 'IONIC_SRC_DIR'; export const ENV_VAR_TMP_DIR = 'IONIC_TMP_DIR'; export const ENV_VAR_WWW_DIR = 'IONIC_WWW_DIR'; +export const ENV_VAR_HTML_TO_SERVE = 'IONIC_HTML_TO_SERVE'; export const ENV_VAR_BUILD_DIR = 'IONIC_BUILD_DIR'; export const ENV_VAR_NODE_MODULES_DIR = 'IONIC_NODE_MODULES_DIR'; export const ENV_VAR_IONIC_ANGULAR_DIR = 'IONIC_ANGULAR_DIR'; @@ -38,6 +38,7 @@ export const ENV_APP_NG_MODULE_CLASS = 'IONIC_APP_NG_MODULE_CLASS'; export const ENV_GLOB_UTIL = 'IONIC_GLOB_UTIL'; export const ENV_CLEAN_BEFORE_COPY = 'IONIC_CLEAN_BEFORE_COPY'; export const ENV_CLOSURE_JAR = 'IONIC_CLOSURE_JAR'; +export const ENV_READ_CONFIG_JSON = 'IONIC_READ_CONFIG_JSON'; export const ENV_OUTPUT_JS_FILE_NAME = 'IONIC_OUTPUT_JS_FILE_NAME'; export const ENV_OUTPUT_JS_MAP_FILE_NAME = 'IONIC_OUTPUT_JS_MAP_FILE_NAME';