Skip to content

Commit

Permalink
fix: ws
Browse files Browse the repository at this point in the history
  • Loading branch information
hai-ko committed Oct 24, 2023
1 parent 3603bde commit dd5d3c6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
4 changes: 3 additions & 1 deletion docker/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ http {
}

location /socket.io {
proxy_pass http://backend:8081/socket.io/;
proxy_pass http://backend:8081/socket.io;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
Expand All @@ -69,5 +69,7 @@ http {
proxy_redirect off;
proxy_set_header Host $host;
}


}
}
18 changes: 9 additions & 9 deletions packages/backend/src/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const pendingMessageSchema = {
export function onConnection(app: express.Application & WithLocals) {
return (socket: Socket) => {
socket.on('disconnect', () => {
app.locals.logger.info({
global.logger.info({
method: 'WS DISCONNECT',
socketId: socket.id,
});
Expand All @@ -36,7 +36,7 @@ export function onConnection(app: express.Application & WithLocals) {
callback,
) => {
try {
app.locals.logger.info({
global.logger.info({
method: 'WS INCOMING MESSAGE',
});

Expand All @@ -48,7 +48,7 @@ export function onConnection(app: express.Application & WithLocals) {
if (!isSchemaValid) {
const error = 'invalid schema';

app.locals.logger.warn({
global.logger.warn({
method: 'WS SUBMIT MESSAGE',
error,
});
Expand All @@ -75,7 +75,7 @@ export function onConnection(app: express.Application & WithLocals) {
),
callback({ response: 'success' });
} catch (error: any) {
app.locals.logger.warn({
global.logger.warn({
method: 'WS SUBMIT MESSAGE',
error: (error as Error).toString(),
});
Expand All @@ -90,7 +90,7 @@ export function onConnection(app: express.Application & WithLocals) {
if (!isSchemaValid) {
const error = 'invalid schema';

app.locals.logger.warn({
global.logger.warn({
method: 'WS PENDING MESSAGE',
error,
});
Expand All @@ -109,15 +109,15 @@ export function onConnection(app: express.Application & WithLocals) {
contactEnsName,
);
} catch (error) {
app.locals.logger.warn({
global.logger.warn({
method: 'WS PENDING MESSAGE',
error,
});

return callback({ error });
}

app.locals.logger.info({
global.logger.info({
method: 'WS PENDING MESSAGE',
ensName,
contactEnsName,
Expand All @@ -132,7 +132,7 @@ export function onConnection(app: express.Application & WithLocals) {
))
) {
const error = 'Token check failed';
app.locals.logger.warn({
global.logger.warn({
method: 'WS PENDING MESSAGE',
error,
});
Expand All @@ -143,7 +143,7 @@ export function onConnection(app: express.Application & WithLocals) {

callback({ response: 'success' });
} catch (error) {
app.locals.logger.warn({
global.logger.warn({
method: 'WS PENDING MESSAGE',
error: (error as Error).toString(),
});
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function socketAuth(app: Express & WithLocals) {
socket.handshake.auth.account.ensName,
);

app.locals.logger.info({
global.logger.info({
method: 'WS CONNECT',
ensName,
socketId: socket.id,
Expand Down
7 changes: 6 additions & 1 deletion packages/lib/delivery/src/Messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ export async function incomingMessage(
getIdEnsName: (name: string) => Promise<string>,
getUsersNotificationChannels: GetNotificationChannels,
): Promise<void> {
logDebug({ text: 'incomingMessage', token });
logDebug({
text: 'incomingMessage',
token,
encryptionKeyPair,
envelop: JSON.stringify(envelop),
});
//Checks the size of the incoming message
if (messageIsToLarge(envelop, sizeLimit)) {
throw Error('Message is too large');
Expand Down
4 changes: 3 additions & 1 deletion packages/messenger-widget/src/components/DM3/DM3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ function DM3(props: Dm3Props) {
throw Error('Could not get account profile');
}

const socket = socketIOClient(deliveryServiceUrl, {


const socket = socketIOClient(deliveryServiceUrl.replace('/api', ''), {
autoConnect: false,
transports: ['websocket'],
});
Expand Down

0 comments on commit dd5d3c6

Please sign in to comment.