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

Cloud function return 404 for /favicon.ico #456

Closed
bananaappletw opened this issue Apr 14, 2022 · 6 comments
Closed

Cloud function return 404 for /favicon.ico #456

bananaappletw opened this issue Apr 14, 2022 · 6 comments
Assignees

Comments

@bananaappletw
Copy link

I use cloud function as a reverse proxy between client(browser) and GCS bucket.

Fetch the GCS bucket object and create readable stream to pipe to client.

When I request /favicon.ico it returns 404.

There's an existing logic to return 404 for /favicon.ico|/robots.txt.

Ref: https://github.com/GoogleCloudPlatform/functions-framework-nodejs/blob/07668f696b29f077d4ba9d0463ea994076cdab50/src/server.ts#L122+L125

I haven't thought about the solution which also fulfill the original purpose, just to provide my use case.

Ref: #193

Thank you.

@anniefu
Copy link
Contributor

anniefu commented Apr 15, 2022

Hey @grant, could you add some context to the history of this here? This may be related #191

@grant
Copy link
Contributor

grant commented Apr 15, 2022

The URL path favicon.ico returns a 404 to prevent double invocation of a user function when invoking via a HTTP browser. Serverless functions should really just handle 1 endpoint for 1 function.

It's typically recommended that you don't use the literal URL path as an input to your function, at least as an input to another URL.


Could your function use a HTTP query param instead, such as localhost:8080/?path=myURL/foo.txt? I believe this should solve the use-case.

@grant
Copy link
Contributor

grant commented Apr 18, 2022

I believe the alternative implementation should satisfy the use-case. LMK if that doesn't work. Closing as WAI but feel free to comment with requested changes and I can re-open if needed.

@grant grant closed this as completed Apr 18, 2022
@bananaappletw
Copy link
Author

bananaappletw commented Apr 18, 2022

@grant Thank you for explanation.

Could your function use a HTTP query param instead

No, I used cloud function as a reverse proxy without any manipulation on the URL.

My intent is that a cloud function should be able dealing with the original request without any extra logic attached on it.

@grant
Copy link
Contributor

grant commented Apr 26, 2022

To follow up here, Cloud Functions is meant to serve and invoke a single function when receiving a HTTP request. The URL path should not be part of the logic of the function. For example, Cloud Functions Gen 1 and Gen 2 have different URL paths.

For this use-case of using URL paths within the function, I would consider using express directly with Cloud Run and not using the Functions Framework.

@eastlondoner
Copy link

Hi @grant I am running into this problem.

Would it be possible to have some configuration option to disable this very specific behaviour where Google Cloud http triggered functions object to serving /favicon.ico

The Google Cloud Firebase documentation has examples of using a Google Cloud Function to host an express web app which literally relies on the URL path - which is at odds with your statement:

the URL path should not be part of the logic of the function

https://firebase.google.com/docs/hosting/functions#use_a_web_framework

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