Skip to content

Commit 6167e41

Browse files
Fix websockets (#12)
* Update codebase with gridstudy * Fix request case * Fix `setupProxy` bad configuration * Add debug option for requests * review
1 parent 7541a1d commit 6167e41

File tree

14 files changed

+82
-53
lines changed

14 files changed

+82
-53
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
EXTEND_ESLINT=true
2+
REACT_APP_DEBUG_REQUESTS=false
23

34
REACT_APP_API_GATEWAY=/api/gateway
45
REACT_APP_WS_GATEWAY=/ws/gateway

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"dependencies": {
1717
"@emotion/react": "^11.8.2",
1818
"@emotion/styled": "^11.8.1",
19-
"@gridsuite/commons-ui": "^0.44.0",
19+
"@gridsuite/commons-ui": "^0.46.0",
2020
"@hookform/resolvers": "^3.3.1",
2121
"@mui/icons-material": "^5.5.1",
2222
"@mui/lab": "^5.0.0-alpha.75",

src/components/app.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ import {
3737
import { AppState } from '../redux/reducer';
3838
import {
3939
ConfigSrv,
40+
ConfigNotif,
4041
ConfigParameter,
4142
ConfigParameters,
4243
UserAdminSrv,
4344
AppsMetadataSrv,
4445
} from '../services';
45-
import { connectNotificationsWsUpdateConfig } from '../utils/rest-api';
4646
import { UserManager } from 'oidc-client';
4747
import {
4848
APP_NAME,
@@ -104,7 +104,7 @@ const App: FunctionComponent = () => {
104104

105105
const connectNotificationsUpdateConfig: () => ReconnectingWebSocket =
106106
useCallback(() => {
107-
const ws = connectNotificationsWsUpdateConfig();
107+
const ws = ConfigNotif.connectNotificationsWsUpdateConfig();
108108
ws.onmessage = function (event) {
109109
let eventData = JSON.parse(event.data);
110110
if (eventData?.headers?.parameterName) {
@@ -174,7 +174,7 @@ const App: FunctionComponent = () => {
174174
})
175175
);
176176

177-
ConfigSrv.fetchConfigParameters(APP_NAME)
177+
ConfigSrv.fetchConfigParameters(APP_NAME.toLowerCase())
178178
.then((params) => updateParams(params))
179179
.catch((error) =>
180180
snackError({

src/services/apps-metadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ReqResponse } from '../utils/rest-api';
1+
import { ReqResponse } from '../utils/api-rest';
22

33
export type EnvJson = typeof import('../../public/env.json');
44

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import ReconnectingWebSocket, { Event } from 'reconnecting-websocket';
2+
import { APP_NAME } from '../utils/config-params';
3+
import { getUrlWithToken, getWsBase } from '../utils/api-ws';
4+
5+
const PREFIX_CONFIG_NOTIFICATION_WS = `${process.env.REACT_APP_WS_GATEWAY}/config-notification`;
6+
7+
export function connectNotificationsWsUpdateConfig(): ReconnectingWebSocket {
8+
const webSocketUrl = `${getWsBase()}${PREFIX_CONFIG_NOTIFICATION_WS}/notify?appName=${APP_NAME.toLowerCase()}`;
9+
const reconnectingWebSocket = new ReconnectingWebSocket(
10+
() => getUrlWithToken(webSocketUrl),
11+
undefined,
12+
{ debug: process.env.REACT_APP_DEBUG_REQUESTS === 'true' }
13+
);
14+
reconnectingWebSocket.onopen = function (event: Event) {
15+
console.info(
16+
`Connected Websocket update config ui ${webSocketUrl} ...`
17+
);
18+
};
19+
return reconnectingWebSocket;
20+
}

src/services/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getAppName } from '../utils/config-params';
2-
import { backendFetch, backendFetchJson } from '../utils/rest-api';
2+
import { backendFetch, backendFetchJson } from '../utils/api-rest';
33

44
const PREFIX_CONFIG_QUERIES = `${process.env.REACT_APP_API_GATEWAY}/config`;
55

src/services/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import * as Config from './config';
2+
import * as ConfigNotif from './config-notification';
23
import * as AppsMetadata from './apps-metadata';
34
import * as Study from './study';
45
import * as UserAdmin from './user-admin';
56

67
const _ = {
78
...Config,
9+
...ConfigNotif,
810
...AppsMetadata,
911
...Study,
1012
...UserAdmin,
@@ -14,6 +16,9 @@ export default _;
1416
export * as ConfigSrv from './config';
1517
export type * from './config';
1618

19+
export * as ConfigNotif from './config-notification';
20+
export type * from './config-notification';
21+
1722
export * as AppsMetadataSrv from './apps-metadata';
1823
export type * from './apps-metadata';
1924

src/services/study.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
7-
import { backendFetchJson, Token } from '../utils/rest-api';
7+
import { backendFetchJson, Token } from '../utils/api-rest';
88

99
const STUDY_URL = `${process.env.REACT_APP_API_GATEWAY}/study/v1`;
1010

src/services/user-admin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { backendFetch, ReqResponse } from '../utils/rest-api';
1+
import { backendFetch, ReqResponse } from '../utils/api-rest';
22

33
const USER_ADMIN_URL = `${process.env.REACT_APP_API_GATEWAY}/user-admin`;
44

0 commit comments

Comments
 (0)