socket.io-client icon indicating copy to clipboard operation
socket.io-client copied to clipboard

Trailing slash in path

Open Stoikiy opened this issue 3 years ago • 3 comments

Describe the bug Version - last stable

So basically i getting the same issue which was raised here in the swift client https://github.com/socketio/socket.io-client-swift/issues/297

if i want to use custom url path, i'm adding it to the options object like: path: '/keka', but in the request url getting /keka/? anyone manage this issue?

Stoikiy avatar Aug 09 '22 13:08 Stoikiy

I am having the same issue as well

dummydamn avatar Sep 08 '22 23:09 dummydamn

Hi! The trailing slash is added there: https://github.com/socketio/engine.io-client/blob/dfee8ded722a8c4f9f773505d0c77b4561569863/lib/socket.ts#L335 (initial commit from 2012: https://github.com/socketio/engine.io-client/commit/93605fd3e950d68130900e37ce0beeceef8eea5c)

I guess we could add an option to include it or not. Could you please explain your use case?

darrachequesne avatar Sep 09 '22 05:09 darrachequesne

if that will be optional in the settings that will be good

Stoikiy avatar Sep 13 '22 10:09 Stoikiy

ping

griffins avatar Jan 16 '23 11:01 griffins

ping

The option is already added at https://github.com/socketio/engine.io-client/commit/21a6e1219add92157c5442537d24fbe1129a50f5

iifawzi avatar Jan 16 '23 11:01 iifawzi

Update: the addTrailingSlash option was added in version 4.6.0:

import { io } from "socket.io-client";

const socket = io("https://example.com", {
  addTrailingSlash: false
});

Reference: https://socket.io/docs/v4/client-options/#addtrailingslash

Please reopen if needed!

darrachequesne avatar Feb 16 '23 08:02 darrachequesne

Update: the addTrailingSlash option was added in version 4.6.0:

import { io } from "socket.io-client";

const socket = io("https://example.com", {
  addTrailingSlash: false
});

Reference: https://socket.io/docs/v4/client-options/#addtrailingslash

Please reopen if needed!

Following issue:

When I use another domain (which is different than my current domain) for example http://localhost:3000, it automatically adds the trailing slash at the end:

http://localhost:3000/socket.io/?EIO=4&transport=polling&t=OrLbOzA&sid=wvjsDtRlP2_P_VulAAAM

Everything seems to be working so far, but when I use my current domain as the host, it automatically removes the trailingSlash at the end and the result is this one http://example.com/socket.io?EIO=4&transport=polling&t=OrLbF-I

and then it tries to add the trailing slash like this: http://example.com/socket.io/?EIO=4&transport=polling&t=OrLbF-I which results to an 308 Permanent Redirect

That's how my configuration looks like:

import { io } from 'socket.io-client';
// obviously I want to use my current domain 
export const socket = (url: string) =>
  io({
    addTrailingSlash: true,
  });

necm1 avatar Jan 29 '24 14:01 necm1

Hi @necm1 , do you know which component returns the HTTP 308 response? nginx?

The addTrailingSlash indeed controls whether a trailing slash is added in the request path:

  • true => http://example.com/socket.io/?EIO=4&...
  • false => http://example.com/socket.io?EIO=4&...

darrachequesne avatar Jan 29 '24 16:01 darrachequesne

Hi @necm1 , do you know which component returns the HTTP 308 response? nginx?

The addTrailingSlash indeed controls whether a trailing slash is added in the request path:

  • true => http://example.com/socket.io/?EIO=4&...
  • false => http://example.com/socket.io?EIO=4&...

I guess NextJS SSR seems to give me the HTTP 308 response (https://nextjs.org/docs/app/api-reference/next-config-js/trailingSlash). I'm using NextJS SSR rewrites as a proxy to my real NestJS backend. I just set addTrailingSlash to false in my backend and it seems to be working now.

Sorry for reopening this issue. I was just confused and thought that socket.io-client removes the trailing slash for the current domain.

necm1 avatar Jan 29 '24 17:01 necm1