Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit e2d0d83

Browse files
committed
fix(http-server): drive reading ionic.config.json based on config value
1 parent 5879a8b commit e2d0d83

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

src/dev-server/http-server.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
import { Logger } from '../logger/logger';
1515
import * as proxyMiddleware from 'proxy-middleware';
1616
import { injectDiagnosticsHtml } from '../logger/logger-diagnostics';
17+
import * as Constants from '../util/constants';
18+
import { getBooleanPropertyValue } from '../util/helpers';
1719
import { getProjectJson, IonicProject } from '../util/ionic-project';
1820

1921
import { LabAppView, ApiCordovaProject } from './lab';
@@ -51,20 +53,23 @@ export function createHttpServer(config: ServeConfig): express.Application {
5153
}
5254

5355
function setupProxies(app: express.Application) {
54-
55-
getProjectJson().then(function(projectConfig: IonicProject) {
56-
for (const proxy of projectConfig.proxies || []) {
57-
let opts: any = url.parse(proxy.proxyUrl);
58-
if (proxy.proxyNoAgent) {
59-
opts.agent = false;
56+
if (getBooleanPropertyValue(Constants.ENV_READ_CONFIG_JSON)) {
57+
getProjectJson().then(function(projectConfig: IonicProject) {
58+
for (const proxy of projectConfig.proxies || []) {
59+
let opts: any = url.parse(proxy.proxyUrl);
60+
if (proxy.proxyNoAgent) {
61+
opts.agent = false;
62+
}
63+
64+
opts.rejectUnauthorized = !(proxy.rejectUnauthorized === false);
65+
66+
app.use(proxy.path, proxyMiddleware(opts));
67+
Logger.info('Proxy added:' + proxy.path + ' => ' + url.format(opts));
6068
}
61-
62-
opts.rejectUnauthorized = !(proxy.rejectUnauthorized === false);
63-
64-
app.use(proxy.path, proxyMiddleware(opts));
65-
Logger.info('Proxy added:' + proxy.path + ' => ' + url.format(opts));
66-
}
67-
});
69+
}).catch((err: Error) => {
70+
Logger.error(`Failed to read the projects ionic.config.json file: ${err.message}`);
71+
});
72+
}
6873
}
6974

7075
/**
@@ -74,7 +79,7 @@ function serveIndex(req: express.Request, res: express.Response) {
7479
const config: ServeConfig = req.app.get('serveConfig');
7580

7681
// respond with the index.html file
77-
const indexFileName = path.join(config.wwwDir, 'index.html');
82+
const indexFileName = path.join(config.wwwDir, process.env[Constants.ENV_VAR_HTML_TO_SERVE]);
7883
fs.readFile(indexFileName, (err, indexHtml) => {
7984
if (config.useLiveReload) {
8085
indexHtml = injectLiveReloadScript(indexHtml, config.host, config.liveReloadPort);

src/util/config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ export function generateContext(context?: BuildContext): BuildContext {
7575
setProcessEnvVar(Constants.ENV_VAR_WWW_DIR, context.wwwDir);
7676
Logger.debug(`wwwDir set to ${context.wwwDir}`);
7777

78-
context.wwwIndex = join(context.wwwDir, Constants.WWW_INDEX_FILENAME);
78+
context.wwwIndex = getConfigValue(context, '--wwwIndex', null, Constants.ENV_VAR_HTML_TO_SERVE, Constants.ENV_VAR_HTML_TO_SERVE.toLowerCase(), 'index.html');
79+
setProcessEnvVar(Constants.ENV_VAR_HTML_TO_SERVE, context.wwwIndex);
7980
Logger.debug(`wwwIndex set to ${context.wwwIndex}`);
8081

8182
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 {
118119
setProcessEnvVar(Constants.ENV_TS_CONFIG, tsConfigPathValue);
119120
Logger.debug(`tsconfig set to ${tsConfigPathValue}`);
120121

122+
const readConfigJson = resolve(getConfigValue(context, '--readConfigJson', null, Constants.ENV_READ_CONFIG_JSON, Constants.ENV_READ_CONFIG_JSON.toLowerCase(), 'true'));
123+
setProcessEnvVar(Constants.ENV_READ_CONFIG_JSON, readConfigJson);
124+
Logger.debug(`readConfigJson set to ${readConfigJson}`);
125+
121126
const appEntryPointPathValue = resolve(getConfigValue(context, '--appEntryPoint', null, Constants.ENV_APP_ENTRY_POINT, Constants.ENV_APP_ENTRY_POINT.toLowerCase(), join(context.srcDir, 'app', 'main.ts')));
122127
setProcessEnvVar(Constants.ENV_APP_ENTRY_POINT, appEntryPointPathValue);
123128
Logger.debug(`appEntryPoint set to ${appEntryPointPathValue}`);

src/util/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export const TMP_DIR = '.tmp';
1313
export const WWW_DIR = 'www';
1414
export const NODE_MODULES = 'node_modules';
1515
export const IONIC_ANGULAR = 'ionic-angular';
16-
export const WWW_INDEX_FILENAME = 'index.html';
1716

1817
export const ENV_VAR_PROD = 'prod';
1918
export const ENV_VAR_DEV = 'dev';
@@ -22,6 +21,7 @@ export const ENV_VAR_ROOT_DIR = 'IONIC_ROOT_DIR';
2221
export const ENV_VAR_SRC_DIR = 'IONIC_SRC_DIR';
2322
export const ENV_VAR_TMP_DIR = 'IONIC_TMP_DIR';
2423
export const ENV_VAR_WWW_DIR = 'IONIC_WWW_DIR';
24+
export const ENV_VAR_HTML_TO_SERVE = 'IONIC_HTML_TO_SERVE';
2525
export const ENV_VAR_BUILD_DIR = 'IONIC_BUILD_DIR';
2626
export const ENV_VAR_NODE_MODULES_DIR = 'IONIC_NODE_MODULES_DIR';
2727
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';
3838
export const ENV_GLOB_UTIL = 'IONIC_GLOB_UTIL';
3939
export const ENV_CLEAN_BEFORE_COPY = 'IONIC_CLEAN_BEFORE_COPY';
4040
export const ENV_CLOSURE_JAR = 'IONIC_CLOSURE_JAR';
41+
export const ENV_READ_CONFIG_JSON = 'IONIC_READ_CONFIG_JSON';
4142

4243
export const ENV_OUTPUT_JS_FILE_NAME = 'IONIC_OUTPUT_JS_FILE_NAME';
4344
export const ENV_OUTPUT_JS_MAP_FILE_NAME = 'IONIC_OUTPUT_JS_MAP_FILE_NAME';

0 commit comments

Comments
 (0)