Kragrathea / pgcode

118 stars 19 forks source link

Support for https #20

Closed RomRider closed 2 years ago

RomRider commented 3 years ago

Hi,

Great project, thanks :)

I'm running all my moonraker instances behind a central https reverse proxy including pgcode itself (traeffik). If pgcode is accessed through https, the ws connection to moonraker has to be over wss:// but currently it's hardcoded as ws:// thus failing with: image

Kragrathea commented 3 years ago

This might be a tough one. I do not have my system on https and wss: does not work for me. I have looked into setting my system up behind https and the cert and config requirements are beyond what I am comfortable doing on Linux. So it will be impossible for me to test. And there may be other issues running https besides the ws/wss.

Here is what I could do. If you want to go in and edit the source file ~/pgcode/printerconnection.js around line 428

let socketUrl = "wss://"+socketHost+"/websocket"+"?token="+result

IF that works for you then I could add an option to the connection dialog to force WSS.

RomRider commented 3 years ago

It's straightforward with that change and works perfectly (I've already forked and tested with the wss hard-coded as I had planned to PR something)

If you want to add a setting, that's good enough, I mainly wanted to see if you had plans for that :)

Kragrathea commented 3 years ago

Will this change work?

` let socketHost=socketUrl.host; if ("WebSocket" in window){ let socketUrl = "ws://"+socketHost+"/websocket"+"?token="+result

           if(serverUrl.toLowerCase().startsWith("https"))
               socketUrl = "wss://"+socketHost+"/websocket"+"?token="+result

`

Sorry, for some reason I can't get the above code to format.

Kragrathea commented 2 years ago

@RomRider I released a change for this. Let me know if it doesn't fix it.