@@ -6,11 +6,13 @@ import express from 'express';
6
6
import path from 'path' ;
7
7
import type { Configuration } from 'webpack-dev-server' ;
8
8
import { HttpsProxyAgent } from 'https-proxy-agent' ;
9
+ import chokidar from 'chokidar' ;
9
10
import cookieTransform from './cookieTransform' ;
10
11
import { matchNavigationRequest } from './feo/check-outgoing-requests' ;
11
12
import { hasFEOFeaturesEnabled , readFrontendCRD } from './feo/crd-check' ;
12
13
import navigationInterceptor from './feo/navigation-interceptor' ;
13
14
import { GeneratedBundles } from './feo/feo-types' ;
15
+ import fecLogger , { LogType } from './fec-logger' ;
14
16
15
17
const defaultReposDir = path . join ( __dirname , 'repos' ) ;
16
18
@@ -134,12 +136,34 @@ const proxy = ({
134
136
localApps = process . env . LOCAL_APPS ,
135
137
frontendCRDPath = path . resolve ( process . cwd ( ) , 'deploy/frontend.yaml' ) ,
136
138
} : ProxyOptions ) => {
137
- const frontendCrd = readFrontendCRD ( frontendCRDPath ) ;
138
- const FEOFeaturesEnabled = hasFEOFeaturesEnabled ( frontendCrd ) ;
139
+ const frontendCrdRef = { current : readFrontendCRD ( frontendCRDPath ) } ;
140
+ const FEOFeaturesEnabled = hasFEOFeaturesEnabled ( frontendCrdRef . current ) ;
139
141
const proxy : ProxyConfigItem [ ] = [ ] ;
140
142
const majorEnv = env . split ( '-' ) [ 0 ] ;
141
143
const defaultLocalAppHost = process . env . LOCAL_APP_HOST || majorEnv + '.foo.redhat.com' ;
142
144
145
+ if ( FEOFeaturesEnabled ) {
146
+ fecLogger ( LogType . info , 'Watching frontend CRC file for changes' ) ;
147
+ const watcher = chokidar . watch ( frontendCRDPath ) . on ( 'change' , ( ) => {
148
+ fecLogger ( LogType . info , 'Frontend CRD has changed, reloading the file' ) ;
149
+ try {
150
+ frontendCrdRef . current = readFrontendCRD ( frontendCRDPath ) ;
151
+ } catch ( error ) {
152
+ fecLogger ( LogType . error , 'Error reloading frontend CRD file' , error ) ;
153
+ }
154
+ } ) ;
155
+
156
+ // close the watcher on webserver shutdown
157
+ process . on ( 'SIGTERM' , ( ) => {
158
+ fecLogger ( LogType . info , 'Closing frontend CRD watcher' ) ;
159
+ watcher . close ( ) ;
160
+ } ) ;
161
+ process . on ( 'SIGINT' , ( ) => {
162
+ fecLogger ( LogType . info , 'Closing frontend CRD watcher' ) ;
163
+ watcher . close ( ) ;
164
+ } ) ;
165
+ }
166
+
143
167
if ( target === '' ) {
144
168
target += 'https://' ;
145
169
if ( ! [ 'prod' , 'stage' ] . includes ( majorEnv ) ) {
@@ -226,7 +250,7 @@ const proxy = ({
226
250
if ( FEOFeaturesEnabled ) {
227
251
// these will be filled in chrome service once migration is ready to start
228
252
objectToModify . forEach ( ( bundle ) => {
229
- const navItems = navigationInterceptor ( frontendCrd , bundle , bundle . id ) ;
253
+ const navItems = navigationInterceptor ( frontendCrdRef . current , bundle , bundle . id ) ;
230
254
resultBundles . push ( { ...bundle , navItems } ) ;
231
255
} ) ;
232
256
}
0 commit comments