Repository navigation
Shouldn't multiple concurent slashes be parsed as a single one? #5355
Unanswered
artem-simutin
asked this question in
Q&A
Replies: 1 comment
|
For this setup, normalize the join between the base URL and namespace before calling let base = BASE_URL;
while (base.endsWith('/')) base = base.slice(0, -1);
const socket = io(base + '/events', {
autoConnect: false,
});This removes only trailing slashes from the base. Avoid replacing repeated slashes across the whole URL, since that would also damage There are two separate concepts here:
// Client
const socket = io(base, {
path: '/events/',
autoConnect: false,
});
// Server
const io = new Server(httpServer, { path: '/events/' });The path documentation distinguishes these and notes that client/server paths must match, unless a proxy rewrites them. The client passes the parsed URL path to the namespace lookup; it is not an application-level URL-joining utility. Removing the duplicate slash fixes the string construction, but you still need to choose namespace versus endpoint correctly. Even a single-slash |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hey! Want to thank you for the amazing work you did on this library.
Today our team faced annoying issue with multiple slashes in the URI that we pass to the
io()call.Here is the basic code:
and this code throws an error: Invalid namespace
The problem is that it will end up:
https://api.example.com//eventswhich will treat/eventsas a namespace which is not correct.Shouldn't it replace all the multiple concurrent slashes to prevent that kind of behavior?
Thank you in advance!
All reactions