Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usinn gotenberg-js-client in firebase function #36

Open
isot1990 opened this issue Oct 22, 2021 · 13 comments
Open

Usinn gotenberg-js-client in firebase function #36

isot1990 opened this issue Oct 22, 2021 · 13 comments

Comments

@isot1990
Copy link

I am trying to use gotenberg-js-client module in a firebase function as below:

**exports.officeToPdf = functions.https.onCall((req, res) => {

const https = require('https');

const {
pipe,
gotenberg,
convert,
url,
please,
} = require('gotenberg-js-client');

const signedUrlOptions = {
// stale options persist even after expiration date
action: 'read',
expires: Date.now() + 1000 * 60 * 2, // invalid date after ten minutes pass
};

const toPDF = pipe(
gotenberg('http://localhost:3000'),
convert,
url,
please,
);

admin
.storage()
.bucket()
.file(req)
.getSignedUrl(signedUrlOptions)
// eslint-disable-next-line promise/always-return
.then(url => {
console.log(url[0]);
// eslint-disable-next-line promise/no-nesting
toPDF(new URL(url[0]))
// eslint-disable-next-line promise/always-return
.then(pdf => {
console.log('ok');
console.log(pdf);
})
.catch(error => {
console.log(error);
});
})
.catch(err => {
console.log(err);
});
});**

but it gives error and it says:

Error: connect ECONNREFUSED 127.0.0.1:3000

I think I need to do something with http://localhost:3000 but I don't know what to do.

Could you help me?

@yumauri
Copy link
Owner

yumauri commented Oct 22, 2021

Hello!
This library is just a client to the Gotenberg tool, hence the name gotenberg-js-client.
This library does not convert anything, it just communicates with running Gotenberg instance, which should be running somewhere...

@isot1990
Copy link
Author

Thank you for your quick answer.

So, can I use it directly on my client side? Or do I need to do extra configuration besides installing package?

@yumauri
Copy link
Owner

yumauri commented Oct 22, 2021

I'm not good at Firebase, but I cannot find anything about is it possible to run Docker image within Firebase infrastructure or not...
Gotenberg works as a Docker container. You should run it somewhere and made it available through Internet. Then you can use its address in gotenberg("...") function.

@isot1990
Copy link
Author

I have decided to use it in a firebase function after I see this advice:

https://stackoverflow.com/a/66278206

but I couldn’t. If I am able to do that it would be perfect. I hope you help me.

@yumauri
Copy link
Owner

yumauri commented Oct 22, 2021

Hm. Actually, I'm not sure why this answer on SO marked as solution, because it doesn't contain any useful information, nor answer to the question...
To use this library you must have a running instance of Gotenberg. This library doesn't work without it.
Gotenberg — is a completely separate and standalone tool, this library doesn't install and run it, this is not possible.
You can compare it with, let's say, MySQL server. NPM package mysql doesn't install MySQL DBMS, it just connects to existing MySQL server.
The same goes with this library — you install and setup Gotenberg somewhere (in Gotenberg issues I saw some guys mentioned CloudRun, but usually you run it within your infrastructure, not cloud).
And once you have working Gotenberg — you can use this library, to use this existing Gotenberg for converting to PDF.

@karatekaneen
Copy link

I have some experience in GCP products and I think (have not tested myself) that Gotenberg would be able to run in Cloud Run without any problems and you should easily be able to run the script you want as a Cloud Function when you have a proper Gotenberg instance running.

Good luck!

@gulien
Copy link

gulien commented Nov 30, 2021

Gotenberg actually works on Cloud Run 😄

@isot1990
Copy link
Author

Do you have any example @gulien? Because I have tried many times but it didn't work unfortunately.

@gulien
Copy link

gulien commented Nov 30, 2021

Did you use the gotenberg/gotenberg:7-cloudrun Docker image? It should work as any other Docker image on Cloud Run.

@isot1990
Copy link
Author

you mean that there is a cloud run version of it, right? If yes, I didnt use it. I will try.

@gulien
Copy link

gulien commented Nov 30, 2021

Exactly! See linked documentation in my first comment 👍

@isot1990
Copy link
Author

Thank you @gulien

@yumauri
Copy link
Owner

yumauri commented Nov 30, 2021

@gulien Oh, thanks for pointing out to documentation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants