Skip to content

Trailing slash in path #1550

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
Stoikiy opened this issue Aug 9, 2022 · 9 comments
Closed

Trailing slash in path #1550

Stoikiy opened this issue Aug 9, 2022 · 9 comments
Labels
enhancement New feature or request
Milestone

Comments

@Stoikiy
Copy link

Stoikiy commented Aug 9, 2022

Describe the bug
Version - last stable

So basically i getting the same issue which was raised here in the swift client
socketio/socket.io-client-swift#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 Stoikiy added the to triage Waiting to be triaged by a member of the team label Aug 9, 2022
@dummydamn
Copy link

I am having the same issue as well

@darrachequesne
Copy link
Member

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

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

@darrachequesne darrachequesne added question Further information is requested and removed to triage Waiting to be triaged by a member of the team labels Sep 9, 2022
@Stoikiy
Copy link
Author

Stoikiy commented Sep 13, 2022

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

@darrachequesne darrachequesne added enhancement New feature or request and removed question Further information is requested labels Sep 19, 2022
darrachequesne pushed a commit to socketio/engine.io-client that referenced this issue Dec 9, 2022
The "addTrailingSlash" option allows to control whether a trailing
slash is added to the path of the HTTP requests created by the library:

- true (default): "/engine.io/"
- false: "/engine.io"

Related: socketio/socket.io-client#1550

Signed-off-by: iifawzi <iifawzie@gmail.com>
@griffins
Copy link

ping

@iifawzi
Copy link

iifawzi commented Jan 16, 2023

ping

The option is already added at socketio/engine.io-client@21a6e12

@darrachequesne
Copy link
Member

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 darrachequesne added this to the 4.6.0 milestone Feb 16, 2023
@necm1
Copy link

necm1 commented Jan 29, 2024

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,
  });

@darrachequesne
Copy link
Member

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:

@necm1
Copy link

necm1 commented Jan 29, 2024

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:

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants