question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to remove the :port from the dev server socket URL to work with reverse proxied connections?

See original GitHub issue

Describe the bug

I raised an issue with connection restarting, but it was closed shortly after it was raised with a related link which doesnt resolve what I think are two separate issues relating to the use of proxied connections.

  1. The page doesnt need to reload if the socket connection fails as it can always be manually reloaded if for any reason the dev socket cant be reached.
  2. the inclusion of the port in the socket URL appears mandatory and isnt useful for reverse proxied applications. Its not entirely clear from the documentation now to remove the port spec to allow a reverse proxy to do the routing from the route url. I have tried changing the port, the host and the path, but how do I just remove the port?

There may be a solution in there: to add config to remove the port, or overrwite the dev server socket URL entire (not just the path spec) to achieve the same.

my nginx configuration takes care of the routing so the client doesnt need to force specification of a port:

server {
    listen 80;
    server_name myviteserver.com;
    location / {
        proxy_pass http://0.0.0.0:3400;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

Thanks

Reproduction

https://reactvite.syntapse.co.uk/

System Info

System:
    OS: Linux 4.19 Alpine Linux
    CPU: (1) x64 Intel Core Processor (Haswell, no TSX)
    Memory: 105.07 MB / 3.76 GB
    Container: Yes
    Shell: 1.33.1 - /bin/ash
  Binaries:
    Node: 16.13.1 - /usr/local/bin/node
    Yarn: 1.22.15 - /usr/local/bin/yarn
    npm: 8.1.2 - /usr/local/bin/npm
  npmPackages:
    @vitejs/plugin-react: ^1.3.0 => 1.3.1
    vite: ^2.9.5 => 2.9.5

Used Package Manager

npm

Logs

No response

Validations

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
laurencefasscommented, Apr 22, 2022

Thanks again for your feedback. It looks a bit strange because Ive got two layers of proxying the outer one managing docker containers (and certificates) and the inner one managing node applications which are effectively running as http/ws. I have only specified the inner reverse proxy in these examples.

I manage my containers with https://hub.docker.com/r/jwilder/nginx-proxy which simplifies my inner nginx proxy management.

0reactions
sapphi-redcommented, Apr 22, 2022

Glad to hear you were able to solve this.

BTW I feel it strange with your nginx config. IIUC you are using vite like below.

browser (https://reactvite.syntapse.co.uk) -> nginx (:443) -> vite (:3400)
browser (wss://reactvite.syntapse.co.uk/socket) -> nginx (:443) -> vite (:3401)

But your nginx config does not have any listen 443 ssl. I do not think it will be able to access with https without it. Was it jusst omitted from the comment?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to remove the port from URL in Webpack Dev Server hot ...
You have to either use different hostname, different port or different both. So either leave backend on http://my-alias:80 and access the ...
Read more >
Server Options - Vite
Set to true to exit if port is already in use, instead of automatically trying the next available port. ... Configure custom proxy...
Read more >
DevServer - webpack
This option allows specifying URL to web socket server (useful when you're proxying dev server and client script does not always know where...
Read more >
WebSocket - Wikipedia
WebSocket is a computer communications protocol, providing full-duplex communication channels over a single TCP connection ... Before WebSocket, port 80 full-duplex communication was...
Read more >
Troubleshooting connection issues | Socket.IO
Problem: the socket is not able to connect​ · You are trying to reach a plain WebSocket server​ · The server is not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found