title: Javascript: How to automatically select http/https and ws/wss?
body: <p>I'm currently developing a small web app and I'm using axios and websockets for dynamically fetching data from the backend. Up until now, I was using <code>"http://" + window.location.host</code> or <code>"ws://" + window.location.host</code> to create relative urls for my backend, so that both frontend and backend could use the correct api in development and deployment. This setup worked perfectly until I added https to the backend server. Now I need different url prefixes (<code>http://</code> and <code>ws://</code> vs <code>https://</code> and <code>wss://</code>) for development and deployment. Is there any way to automatically select the right protocol for each environment?</p>