Skip to content

Commit 42f809f

Browse files
committed
♻️(frontend) get collaboration server url from config endpoint
We centralized the configuration on the backend side, it is easier to manage and we can change the configuration without having to rebuild the frontend. We now use the config endpoint to get the collaboration server url, we refacto to remove the frontend env occurences and to adapt with the new way to get the collaboration server url.
1 parent 7d64c82 commit 42f809f

File tree

12 files changed

+56
-24
lines changed

12 files changed

+56
-24
lines changed

src/frontend/Dockerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ FROM impress AS impress-builder
6161

6262
WORKDIR /home/frontend/apps/impress
6363

64-
ARG Y_PROVIDER_URL
65-
ENV NEXT_PUBLIC_Y_PROVIDER_URL=${Y_PROVIDER_URL}
66-
6764
ARG API_ORIGIN
6865
ENV NEXT_PUBLIC_API_ORIGIN=${API_ORIGIN}
6966

src/frontend/apps/e2e/__tests__/app-impress/config.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,26 @@ test.describe('Config', () => {
110110
/http:\/\/localhost:8083\/media\/.*\/attachments\/.*.png/,
111111
);
112112
});
113+
114+
test('it checks that collaboration server is configured from config endpoint', async ({
115+
page,
116+
browserName,
117+
}) => {
118+
const webSocketPromise = page.waitForEvent('websocket', (webSocket) => {
119+
return webSocket.url().includes('ws://localhost:4444/');
120+
});
121+
122+
await page.goto('/');
123+
124+
const randomDoc = await createDoc(
125+
page,
126+
'doc-collaboration',
127+
browserName,
128+
1,
129+
);
130+
await expect(page.locator('h2').getByText(randomDoc[0])).toBeVisible();
131+
132+
const webSocket = await webSocketPromise;
133+
expect(webSocket.url()).toContain('ws://localhost:4444/');
134+
});
113135
});

src/frontend/apps/impress/.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
NEXT_PUBLIC_API_ORIGIN=
2-
NEXT_PUBLIC_Y_PROVIDER_URL=
32
NEXT_PUBLIC_SW_DEACTIVATED=
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
NEXT_PUBLIC_API_ORIGIN=http://localhost:8071
2-
NEXT_PUBLIC_Y_PROVIDER_URL=ws://localhost:4444
32
NEXT_PUBLIC_SW_DEACTIVATED=true

src/frontend/apps/impress/src/core/conf.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,3 @@ export const backendUrl = () =>
44

55
export const baseApiUrl = (apiVersion: string = '1.0') =>
66
`${backendUrl()}/api/v${apiVersion}/`;
7-
8-
export const providerUrl = (docId: string) => {
9-
const base =
10-
process.env.NEXT_PUBLIC_Y_PROVIDER_URL ||
11-
(typeof window !== 'undefined' ? `wss://${window.location.host}/ws` : '');
12-
13-
return `${base}/${docId}`;
14-
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './useMediaUrl';
2+
export * from './useCollaborationUrl';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { useConfig } from '../api';
2+
3+
export const useCollaborationUrl = (room?: string) => {
4+
const { data: conf } = useConfig();
5+
6+
if (!room) {
7+
return;
8+
}
9+
10+
const base =
11+
conf?.COLLABORATION_SERVER_URL ||
12+
(typeof window !== 'undefined' ? `wss://${window.location.host}/ws` : '');
13+
14+
return `${base}/${room}`;
15+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './AppProvider';
22
export * from './auth';
33
export * from './conf';
4+
export * from './config';

src/frontend/apps/impress/src/custom-next.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ declare module '*.svg?url' {
2020
namespace NodeJS {
2121
interface ProcessEnv {
2222
NEXT_PUBLIC_API_ORIGIN?: string;
23-
NEXT_PUBLIC_Y_PROVIDER_URL?: string;
2423
NEXT_PUBLIC_SW_DEACTIVATED?: string;
2524
}
2625
}

src/frontend/apps/impress/src/features/docs/doc-editor/components/DocEditor.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import React, { useEffect } from 'react';
44
import { useTranslation } from 'react-i18next';
55

66
import { Box, Card, Text, TextErrors } from '@/components';
7+
import { useCollaborationUrl } from '@/core';
78
import { useCunninghamTheme } from '@/cunningham';
89
import { DocHeader } from '@/features/docs/doc-header';
910
import { Doc, useDocStore } from '@/features/docs/doc-management';
@@ -98,19 +99,20 @@ export const DocVersionEditor = ({ doc, versionId }: DocVersionEditorProps) => {
9899
versionId,
99100
});
100101
const { createProvider, providers } = useDocStore();
102+
const collaborationUrl = useCollaborationUrl(versionId);
101103

102104
const { replace } = useRouter();
103105

104106
useEffect(() => {
105-
if (!version?.id) {
107+
if (!version?.id || !collaborationUrl) {
106108
return;
107109
}
108110

109111
const provider = providers?.[version.id];
110112
if (!provider || provider.document.guid !== version.id) {
111-
createProvider(version.id, version.content);
113+
createProvider(collaborationUrl, version.id, version.content);
112114
}
113-
}, [createProvider, providers, version]);
115+
}, [createProvider, providers, version, collaborationUrl]);
114116

115117
if (isError && error) {
116118
if (error.status === 404) {

0 commit comments

Comments
 (0)