sindresorhus/opn

Do you want to work on this issue?

You can request for a bounty in order to promote it!

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

mazenhilal posted onGitHub

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.


same issue Any solution or alternative till now.

posted by gdeepak884 almost 4 years ago

same issue here

posted by adrielbustos over 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...

posted by gabrielpasini over 3 years ago

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

posted by studiotimo almost 3 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

posted by adrielbustos almost 3 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);
});
posted by studiotimo almost 3 years ago

Same issue Please suggest any solutions or provide some alternatives .

posted by ravi-kumar5-kiwitech over 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 .

posted by ravi-kumar5-kiwitech over 2 years 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

posted by MhdSadd almost 2 years ago

Fund this Issue

$0.00
Funded
Only logged in users can fund an issue

Pull requests