Back

[SOLVED] Cloud function executes twice from the URL

  • 0
  • Functions
  • Cloud
Matej
29 Sep, 2023, 19:37

When go to my function URL, it executes twice.

/favicon.ico path always being the second execution.

Why is that happening?

TL;DR
Cloud function is executing twice from the URL. The issue was resolved by adding a return statement to a utility call. The user then questioned if the redirection code should be in the main method or the utility function. It was suggested that the redirection code should be placed in the main method if it is not working in the utility function. However, the user still faced the issue of the code being executed twice when opening it in a browser, with the /favicon.ico path being the second execution. The reason for this behavior is that browsers automatically fetch the favicon.
Drake
29 Sep, 2023, 19:39

browsers automatically fetch favicon

Matej
29 Sep, 2023, 19:39

Ah, so I can't do anything about this?

Binyamin
29 Sep, 2023, 19:40

You can check the path and return nothing at start so it will finish as fast as possible

Drake
29 Sep, 2023, 19:40

not if you're opening it with a browser

Matej
29 Sep, 2023, 19:40

Well, still goes to execution count. πŸ˜„

Binyamin
29 Sep, 2023, 19:40

Ooh for that part Yes..

Matej
29 Sep, 2023, 19:43

Another thing

At some point I do return res.redirect(new URL(document.url)); Shouldn't this redirect me, in the browser, to the url that is set in here?

Matej
29 Sep, 2023, 19:44

If I run it from the browser

Drake
29 Sep, 2023, 19:46

yes? depends on how you've done it

Matej
29 Sep, 2023, 20:00

redirection is inside a utility function that is in another file. It doesn't redirect even tho it comes and executes that line of code.

Should redirect part rather be in the main method in main.ts rather than in the utility?

Matej
29 Sep, 2023, 20:02

Nevermind

Matej
29 Sep, 2023, 20:02

I actually forgot a return statement on utility call. It works. Ty

Matej
29 Sep, 2023, 20:03

[SOLVED] Cloud function executes twice from the URL

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more