@@ -14,6 +14,8 @@ import {
14
14
import { Logger } from '../logger/logger' ;
15
15
import * as proxyMiddleware from 'proxy-middleware' ;
16
16
import { injectDiagnosticsHtml } from '../logger/logger-diagnostics' ;
17
+ import * as Constants from '../util/constants' ;
18
+ import { getBooleanPropertyValue } from '../util/helpers' ;
17
19
import { getProjectJson , IonicProject } from '../util/ionic-project' ;
18
20
19
21
import { LabAppView , ApiCordovaProject } from './lab' ;
@@ -51,20 +53,23 @@ export function createHttpServer(config: ServeConfig): express.Application {
51
53
}
52
54
53
55
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 ) ) ;
60
68
}
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
+ }
68
73
}
69
74
70
75
/**
@@ -74,7 +79,7 @@ function serveIndex(req: express.Request, res: express.Response) {
74
79
const config : ServeConfig = req . app . get ( 'serveConfig' ) ;
75
80
76
81
// 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 ] ) ;
78
83
fs . readFile ( indexFileName , ( err , indexHtml ) => {
79
84
if ( config . useLiveReload ) {
80
85
indexHtml = injectLiveReloadScript ( indexHtml , config . host , config . liveReloadPort ) ;
0 commit comments