Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

How to connect to a different domain #30

Open
Arshia76 opened this issue Nov 2, 2023 · 4 comments
Open

How to connect to a different domain #30

Arshia76 opened this issue Nov 2, 2023 · 4 comments

Comments

@Arshia76
Copy link

Arshia76 commented Nov 2, 2023

Hi, I want to connect to a different domain other than the one on my localhost because backend will be deployed in other platform,
but it seems that it only connects to the local platform (the one front runs on).
I,ve seen that there is createConnection function to change it's urlConfig but not quite sure how to do,
can you please tell if it is possible and if yes how?
Thanks in advance

@nitedani
Copy link
Owner

nitedani commented Nov 4, 2023

Hi!

It should be possible like so:

  const { socket } = useSocket("https://some.domain.com", {
      // other options
  });
  const { lastMessage } = useSocketEvent<string>(socket, "message", {
    onMessage: (message) => console.log(message),
  });

@Arshia76
Copy link
Author

Arshia76 commented Nov 6, 2023

Hi, thanks just a side note does the code above take the port number into account.
Because in development back and front both running in localhost but different ports
const {socket} = useSocket("http://localhost:5000,{//options})
i mean does this code works as expected?
cause i tried it and it was always sending request to localhost:3000 (front part)
is there anywhere to set port specifically?
or is it ok to put it only like above without specific options (like the port in options)

@nitedani
Copy link
Owner

nitedani commented Nov 6, 2023

This is a weird one. I tried passing the host and port options to the socketIo constructor, like so: io({host: "some.domain.com", port: 1234}), but it still tries to connect to localhost. I'm not sure this is something I can fix in my library, but I will have another look later. Your example, passing the port in the first string parameter, works.

@Arshia76
Copy link
Author

Arshia76 commented Nov 9, 2023

I see, anyway i'll give it a try and let you know of my result
Thanks for your answer by the way
highly appreciate it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants