Hi all, I am having a problem with creating a ‘Deploy to DO’ button for my app on the APP Platform. I am having a socket.io/node.js application and I need to pass an environment variable on my client-side:

let socket = io.connect('https://some-url.com', {
    reconnection: false,
    transports: ['websocket'],
    upgrade: false
});

I need to add an environment variable to pass the URL upon the deployment of the app. I tried with ${APP_URL} and with process.env.APP_URL but neither of those seems to work.

Thanks in advance!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hey all, I somehow managed to use a workaround and I’m sharing it here in case somebody faces the same problem. I used the following code:

let url = window.location.href;
const {hostname} = new URL(url);

let socket = io.connect(`https://${hostname}`, {
    reconnection: false,
    transports: ['websocket'],
    upgrade: false
});

I am defining a variable to get the current URL, then I am using the URL constructor to extract the URL. I am then making a string with https://${hostname} to put the URL in use.