sindresorhus / open

Open stuff like URLs, files, executables. Cross-platform.
MIT License
3.19k stars 224 forks source link

open(url) is working on localhost but not working in production #248

Open mazenhilal opened 3 years ago

mazenhilal commented 3 years ago

Hello, The open(url) is not working in production, though it's working perfectly on localhost. I am using the latest version 8.0.8 and have a MEAN stack app (node backend) running on Elastic Beanstalk. Also, I am not getting any errors to understand what's happening. Has anyone faced a similar issue? Thanks.

gdeepak884 commented 3 years ago

same issue Any solution or alternative till now.

adrielbustos commented 3 years ago

same issue here

gabrielpasini commented 3 years ago

Same issue here! I'm using node backend hosted in Heroku and open(url) doesn't work 😢 on localhost it works perfectly...

studiotimo commented 2 years ago

I ran into this issue. Worked great only on localhost. Are there any solutions for this or alternatives?

adrielbustos commented 2 years ago

I had to do this for a work. I tried to use heroku, google cloud, amazon but any does not worked. So I think, do not exists any solution for this. I had to do an application with Electron Js, register a protocol and send a build to the client. This is the code for that app, I hope it helps you: https://github.com/adrielbustos/docuedit/blob/main/index.js

studiotimo commented 2 years ago

Thank you.

Not sure if this is a good solution, but res.redirect() in express.js seems to work for my case, as I was doing this inside of an API endpoint – attaching a snippet below. Context: I was building an OAuth2 authentication flow and wanted to show the OAuth consent screen by using open.

let oauth2Client;

app.get('/my-app/auth', (req, res) => {
  oauth2Client = new google.auth.OAuth2(<CLIENT-ID>, <CLIENT-SECRET>, <CALLBACK-URI>);

  const authorizeUrl = oauth2Client.generateAuthUrl({
    access_type: 'offline',
    prompt: 'consent',
    scope: <SCOPE(s)>,
  });

  // open(authorizeUrl, {wait: false}).then(cp => cp.unref()); // 'open' works on localhost, but not on the server
  res.redirect(authorizeUrl);
});
ravi-kumar5-kiwitech commented 2 years ago

Same issue Please suggest any solutions or provide some alternatives .

ravi-kumar5-kiwitech commented 2 years ago

open("http://example.com/") if you are opening any URL using open library in backend , it will always open URL on server side not on client side .That is why it is work properly in localhost and not on server . Because localhost has same server and client . On server side , open always open URL on server's default browser .

MhdSadd commented 1 year ago

has any found a solution to this, I've been trying to use this on strapi CMS admin, just as @mazenhilal It works fine on localhost but won't open the URI when on digitalocean app platform. If it's impossible to use this from the server side what alternatives does one have