Skip to content

Commit

Permalink
🚚(frontend) add routes "/collaboration/ws/poll/"
Browse files Browse the repository at this point in the history
We add the routes "/collaboration/ws/poll/".
We updated the useCollaborationUrl hook to
return the new route.
We update ngnix to accept OPTIONS requests.
  • Loading branch information
AntoLC committed Dec 24, 2024
1 parent d7a12eb commit e5b9151
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
8 changes: 8 additions & 0 deletions docker/files/etc/nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ server {

# Proxy auth for collaboration server
location /collaboration/ws/ {
if ($request_method = OPTIONS) {
add_header 'Access-Control-Allow-Origin' 'http://localhost:3000';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type';
return 204;
}

# Collaboration Auth request configuration
auth_request /collaboration-auth;
auth_request_set $authHeader $upstream_http_authorization;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { useConfig } from '../api';

export const useCollaborationUrl = (room?: string) => {
export type CollaborationUrl = {
wsUrl: string;
pollUrl: string;
};

export const useCollaborationUrl = (
room?: string,
): CollaborationUrl | undefined => {
const { data: conf } = useConfig();

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

return `${base}?room=${room}`;
const wsUrl = `${base}?room=${room}`;

let pollUrl = wsUrl.replace('/ws/', '/ws/poll/');
pollUrl = pollUrl.replace('ws:', 'http:');
if (pollUrl.includes('wss:')) {
pollUrl = pollUrl.replace('wss:', 'https:');
}

return { wsUrl, pollUrl };
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ export const useCollaboration = (room?: string, initialContent?: Base64) => {
const { provider, createProvider, destroyProvider } = useProviderStore();

useEffect(() => {
if (!room || !collaborationUrl || provider) {
if (!room || !collaborationUrl?.wsUrl || provider) {
return;
}

const newProvider = createProvider(collaborationUrl, room, initialContent);
const newProvider = createProvider(
collaborationUrl.wsUrl,
room,
initialContent,
);
setBroadcastProvider(newProvider);
}, [
provider,
collaborationUrl,
collaborationUrl?.wsUrl,
room,
initialContent,
createProvider,
Expand Down

0 comments on commit e5b9151

Please sign in to comment.