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

Feature request: Configurable WebSocket location #10

Open
allan2 opened this issue Nov 22, 2023 · 2 comments
Open

Feature request: Configurable WebSocket location #10

allan2 opened this issue Nov 22, 2023 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@allan2
Copy link

allan2 commented Nov 22, 2023

I would like to use Nginx in front of Trunk when developing, but I am encountering some problems with autoreload.

Trunk serves on [::1]:8080. I would like to be able to use both of these configurations:

  • subdomain: (app.example.com)
  • non-root path: (example.com/app)

subdomain setup (app.example.com)

server {
    ...

    server_name app.example.com;
    
    location / {
        proxy_pass http://[::1]:8080;
    }
    
    location /_trunk/ws {
        proxy_pass http://[::1]:8080;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_http_version 1.1;
    }
}

non-root-path setup (example.com/app)

server {
    ...

    server_name example.com;
    
    location / {
        ...  # do other things
    }
    
   location /app/ {
        proxy_pass http://[::1]:8080;
    }
    
    location /app/_trunk/ws {
        proxy_pass http://[::1]:8080;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_http_version 1.1;
    }
}

In this setup, public_url must be set in Trunk.toml for the SPA to load:

[Build]
public_url = "/app/"

The SPA must also be made aware of the pathname to route properly.

In this configuration, Trunk is looking for the WS socket in the wrong place at https://example.com/_trunk/ws. This affects both thedodd/trunk and ctron/trunk.

It would be nice if the socket location also followed public_url or if it could be configured separately.

(I filed this issue here instead of upstream because it seems more active)

Thank you!

@ctron ctron added bug Something isn't working help wanted Extra attention is needed labels Nov 24, 2023
@ctron
Copy link
Owner

ctron commented Nov 24, 2023

I think that's a regression by the PR from trunk-rs#500, and it should be fixed on main. … But also the second case never worked.

So yes, I think it makes sense to somehow make this configurable. As we have a ws_protocol argument, we could also add a ws_url (or ws_address?) argument.

As you seem to have a working setup for this, it would be great if you could give it a try.

@allan2
Copy link
Author

allan2 commented Nov 30, 2023

Thanks! I intend to submit a PR in the coming days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants