wailsapp / wails

Create beautiful applications using Go
https://wails.io
MIT License
25.25k stars 1.22k forks source link

reverse proxy wss /wails/ipc #2436

Open zuiwuchang opened 1 year ago

zuiwuchang commented 1 year ago

Description

The ipc.js injected by wails dev uses the following code to create the websocket:

new WebSocket("ws://"+window.location.host+"/wails/ipc"

This makes it impossible to call the code provided by go in js when using https to access devserver, because the browser refuses to access ws (ws://YourHost/wails/ipc) from https

The websocket should be created using something like the following code:

new WebSocket((window.location.protocol.indexOf("https") > -1 ? "wss://" : "ws://") + window.location.host + "/wails/ipc")

Usually don't use https to access the devserver, but this is indeed a bug and there is such a need, such as me.

I use code-server for remote development so that I can remotely develop company projects even at home. For safety, I use envoy+https for all http to provide security guarantees, but now the wrong code injected by wails dev makes it impossible to pass https correct access devserver.

To Reproduce

  1. wails dev run dev
  2. Use a reverse proxy like envoy/nginx to provide https for devserver
  3. Access the devserver using https in the browser

Expected behaviour

You can use the reverse proxy to provide secure access to https for devserver

Screenshots

wss

Attempted Fixes

https://github.com/wailsapp/wails/issues?q=wss

System Details

dev@ubuntu:~$ wails doctor
Wails CLI v2.3.1

Scanning system - Please wait (this may take a long time)...Done.

# System

OS           | Ubuntu
Version      | 22.04
ID           | ubuntu
Go Version   | go1.19.5
Platform     | linux
Architecture | amd64

# Wails

Version         | v2.3.1
Package Manager | apt

# Dependencies

Dependency | Package Name          | Status    | Version
*docker    | docker.io             | Available | 20.10.12-0ubuntu4
gcc        | build-essential       | Installed | 11.3.0
libgtk-3   | libgtk-3-dev          | Installed | 3.24.33-1ubuntu2
libwebkit  | libwebkit2gtk-4.0-dev | Installed | 2.38.5-0ubuntu0.22.04.1
npm        | npm                   | Installed | 9.5.1
*nsis      | nsis                  | Installed | v3.08-2
pkg-config | pkg-config            | Installed | 0.29.2-1ubuntu3
* - Optional Dependency

# Diagnosis

Your system is ready for Wails development!
Optional package(s) installation details:
  - docker: sudo apt install docker.io

 ♥   If Wails is useful to you or your company, please consider sponsoring the project:
https://github.com/sponsors/leaanthony

Additional context

No response

leaanthony commented 1 year ago

If @stffabi has no objections and you're willing to make a PR then we can look at getting it in.

stffabi commented 1 year ago

I'm fine if we change that.

zuiwuchang commented 1 year ago

If @stffabi has no objections and you're willing to make a PR then we can look at getting it in.

I'd love to get my hands dirty and fix this bug, but I'm new to wails, I actually only started with wails 3 days ago. So I am not sure about the project structure and where to modify this code. After I understand the wails code structure better, if this problem is not fixed, then I will submit a fix code.

learncodingforweb commented 1 year ago

i am also facing same issue on ubuntu #47~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Jun 21 15:35:31 UTC 2 wails doctor ouput is

Wails CLI v2.5.1

 SUCCESS  Done.                                                                                              

# System

OS           | Ubuntu  
Version      | 22.04   
ID           | ubuntu  
Go Version   | go1.20.5
Platform     | linux   
Architecture | amd64   

# Wails

Version         | v2.5.1
Package Manager | apt   

# Dependencies

Dependency | Package Name          | Status    | Version                
*docker    | docker.io             | Installed | 24.0.4                 
gcc        | build-essential       | Installed | 12.9ubuntu3            
libgtk-3   | libgtk-3-dev          | Installed | 3.24.33-1ubuntu2       
libwebkit  | libwebkit2gtk-4.0-dev | Installed | 2.38.6-0ubuntu0.22.04.1
npm        | npm                   | Installed | 8.19.2                 
*nsis      | nsis                  | Installed | v3.08-2                
pkg-config | pkg-config            | Installed | 0.29.2-1ubuntu3        
* - Optional Dependency

when try to connect socket io const sock = io("ws://localhost:8000", {path: '/web/socket.io/'});

Solution tried, if try to run on browser like chrome and mozilla, it is working fine. but on wails app getting WebSocket connection to 'wss://wails.localhost:34115/_next/webpack-hmr' failed: