Skip to content

Commit 77a8ffe

Browse files
committedJan 28, 2025··
fix(config-utils): watch for frontend CRD changes in proxy
1 parent 1735da1 commit 77a8ffe

File tree

4 files changed

+58
-4
lines changed

4 files changed

+58
-4
lines changed
 

‎package-lock.json

+29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/config-utils/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@openshift/dynamic-plugin-sdk-webpack": "^4.0.1",
2828
"ajv": "^8.17.1",
2929
"chalk": "^4.1.2",
30+
"chokidar": "^4.0.3",
3031
"js-yaml": "^4.1.0",
3132
"node-fetch": "2.6.7"
3233
},

‎packages/config-utils/src/proxy.ts

+27-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import express from 'express';
66
import path from 'path';
77
import type { Configuration } from 'webpack-dev-server';
88
import { HttpsProxyAgent } from 'https-proxy-agent';
9+
import chokidar from 'chokidar';
910
import cookieTransform from './cookieTransform';
1011
import { matchNavigationRequest } from './feo/check-outgoing-requests';
1112
import { hasFEOFeaturesEnabled, readFrontendCRD } from './feo/crd-check';
1213
import navigationInterceptor from './feo/navigation-interceptor';
1314
import { GeneratedBundles } from './feo/feo-types';
15+
import fecLogger, { LogType } from './fec-logger';
1416

1517
const defaultReposDir = path.join(__dirname, 'repos');
1618

@@ -134,12 +136,34 @@ const proxy = ({
134136
localApps = process.env.LOCAL_APPS,
135137
frontendCRDPath = path.resolve(process.cwd(), 'deploy/frontend.yaml'),
136138
}: ProxyOptions) => {
137-
const frontendCrd = readFrontendCRD(frontendCRDPath);
138-
const FEOFeaturesEnabled = hasFEOFeaturesEnabled(frontendCrd);
139+
const frontendCrdRef = { current: readFrontendCRD(frontendCRDPath) };
140+
const FEOFeaturesEnabled = hasFEOFeaturesEnabled(frontendCrdRef.current);
139141
const proxy: ProxyConfigItem[] = [];
140142
const majorEnv = env.split('-')[0];
141143
const defaultLocalAppHost = process.env.LOCAL_APP_HOST || majorEnv + '.foo.redhat.com';
142144

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+
143167
if (target === '') {
144168
target += 'https://';
145169
if (!['prod', 'stage'].includes(majorEnv)) {
@@ -226,7 +250,7 @@ const proxy = ({
226250
if (FEOFeaturesEnabled) {
227251
// these will be filled in chrome service once migration is ready to start
228252
objectToModify.forEach((bundle) => {
229-
const navItems = navigationInterceptor(frontendCrd, bundle, bundle.id);
253+
const navItems = navigationInterceptor(frontendCrdRef.current, bundle, bundle.id);
230254
resultBundles.push({ ...bundle, navItems });
231255
});
232256
}

‎packages/config/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"scripts": {},
2828
"dependencies": {
2929
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
30-
"@redhat-cloud-services/frontend-components-config-utilities": "^4.0.4",
30+
"@redhat-cloud-services/frontend-components-config-utilities": "^4.1.0",
3131
"@redhat-cloud-services/tsc-transform-imports": "^1.0.21",
3232
"@swc/core": "^1.3.76",
3333
"assert": "^2.0.0",

0 commit comments

Comments
 (0)
Please sign in to comment.