Skip to content

Commit e5b9151

Browse files
committed
🚚(frontend) add routes "/collaboration/ws/poll/"
We add the routes "/collaboration/ws/poll/". We updated the useCollaborationUrl hook to return the new route. We update ngnix to accept OPTIONS requests.
1 parent d7a12eb commit e5b9151

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

docker/files/etc/nginx/conf.d/default.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ server {
66

77
# Proxy auth for collaboration server
88
location /collaboration/ws/ {
9+
if ($request_method = OPTIONS) {
10+
add_header 'Access-Control-Allow-Origin' 'http://localhost:3000';
11+
add_header 'Access-Control-Allow-Credentials' 'true';
12+
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
13+
add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type';
14+
return 204;
15+
}
16+
917
# Collaboration Auth request configuration
1018
auth_request /collaboration-auth;
1119
auth_request_set $authHeader $upstream_http_authorization;

src/frontend/apps/impress/src/core/config/hooks/useCollaborationUrl.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { useConfig } from '../api';
22

3-
export const useCollaborationUrl = (room?: string) => {
3+
export type CollaborationUrl = {
4+
wsUrl: string;
5+
pollUrl: string;
6+
};
7+
8+
export const useCollaborationUrl = (
9+
room?: string,
10+
): CollaborationUrl | undefined => {
411
const { data: conf } = useConfig();
512

613
if (!room) {
@@ -13,5 +20,13 @@ export const useCollaborationUrl = (room?: string) => {
1320
? `wss://${window.location.host}/collaboration/ws/`
1421
: '');
1522

16-
return `${base}?room=${room}`;
23+
const wsUrl = `${base}?room=${room}`;
24+
25+
let pollUrl = wsUrl.replace('/ws/', '/ws/poll/');
26+
pollUrl = pollUrl.replace('ws:', 'http:');
27+
if (pollUrl.includes('wss:')) {
28+
pollUrl = pollUrl.replace('wss:', 'https:');
29+
}
30+
31+
return { wsUrl, pollUrl };
1732
};

src/frontend/apps/impress/src/features/docs/doc-management/hooks/useCollaboration.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ export const useCollaboration = (room?: string, initialContent?: Base64) => {
1212
const { provider, createProvider, destroyProvider } = useProviderStore();
1313

1414
useEffect(() => {
15-
if (!room || !collaborationUrl || provider) {
15+
if (!room || !collaborationUrl?.wsUrl || provider) {
1616
return;
1717
}
1818

19-
const newProvider = createProvider(collaborationUrl, room, initialContent);
19+
const newProvider = createProvider(
20+
collaborationUrl.wsUrl,
21+
room,
22+
initialContent,
23+
);
2024
setBroadcastProvider(newProvider);
2125
}, [
2226
provider,
23-
collaborationUrl,
27+
collaborationUrl?.wsUrl,
2428
room,
2529
initialContent,
2630
createProvider,

0 commit comments

Comments
 (0)