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

Commit

Permalink
fix(http-server): drive reading ionic.config.json based on config value
Browse files Browse the repository at this point in the history
  • Loading branch information
danbucholtz committed Feb 15, 2017
1 parent 5879a8b commit e2d0d83
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
33 changes: 19 additions & 14 deletions src/dev-server/http-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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}`);
});
}
}

/**
Expand All @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion src/util/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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}`);
Expand Down
3 changes: 2 additions & 1 deletion src/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand All @@ -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';
Expand Down

0 comments on commit e2d0d83

Please sign in to comment.