calzoneman / sync

Node.JS Server and JavaScript/HTML Client for synchronizing online media
Other
1.45k stars 235 forks source link

Set port for IO URL generation without having to listen on that port #930

Closed rezafouladian closed 2 years ago

rezafouladian commented 2 years ago

Server Problem

Please confirm whether you've tried the following debugging steps:

Description of the Problem

If I want to have the IO port run on 1337, but then connect via port 443 through a proxy service, I have to set it to listen on both 443 and 1337, for example:

  - ip: ''
    port: 443
    io: true
  - ip: ''
    port: 1337
    io: true

Without the extra port definition, the server tries to have clients access through https://io.example.com:1337 when they need to access through https://io.example.com:443 There's also a default-port setting under the IO config block, but this doesn't seem to have any effect on the URL regardless of other settings.

The only way to do this without defining a second IO port seems to be changing srv.port to "443". https://github.com/calzoneman/sync/blob/0d9f4a5f038358430fa4b63a69cd2a42aa48b0cb/src/config.js#L326 When that is hardcoded, the server works fine listening on only 1337 and proxied via 443.

Is it possible to add a config option to manually set the port for URL generation? Or maybe I'm missing something?

System Information

calzoneman commented 2 years ago

Instead of trying to muck with the URL generation logic, it may be easier for you to patch the code to hardcode the URL itself. It looks like you already found the right place to do that.

Ultimately, it ends up getting used in the endpoint config shipped to the client https://github.com/calzoneman/sync/blob/3.0/src/configuration/ioconfig.js; I suppose another strategy besides overriding individual URLs would be to just migrate the IO endpoint config to its own hand-edited file instead of generating it (which is how it is managed for the undocumented cluster mode).

rezafouladian commented 2 years ago

Alright, I guess my year old config file was missing one of the commented out examples (or maybe I deleted it), but I guess I was stupid and the url option was available the entire time.

# Default Socket.IO server - default interface, port 1337
  - ip: ''
    port: 1337
    io: true
    url: 'https://io.example.com:443'
calzoneman commented 2 years ago

Oh, I forgot that was even supported. Well, I'm glad you got it figured out.