@@ -14,6 +14,8 @@ import {
1414import { Logger } from '../logger/logger' ;
1515import * as proxyMiddleware from 'proxy-middleware' ;
1616import { injectDiagnosticsHtml } from '../logger/logger-diagnostics' ;
17+ import * as Constants from '../util/constants' ;
18+ import { getBooleanPropertyValue } from '../util/helpers' ;
1719import { getProjectJson , IonicProject } from '../util/ionic-project' ;
1820
1921import { LabAppView , ApiCordovaProject } from './lab' ;
@@ -51,20 +53,23 @@ export function createHttpServer(config: ServeConfig): express.Application {
5153}
5254
5355function 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 ) ;
0 commit comments