0
votes

Firebase Hosting can process dynamic requests with Cloud Functions. This works well, however if the page does not exist I'd like to show the 404.html page of the static site.

I cannot simply redirect to it, because then the 404 page is shown, but the status is 200.

I can return 404 from Flask with:

  return "Not found", 404

but then only the Not found text is printed.

How can I return the 404.html file and return the 404 code at the same time from Flask? Does a Cloud Function invoked by Firebase Hosting "see" the files of the static site?

1

1 Answers

1
votes

I searched for a solution and found that the cloud function cannot access the hosted files. But it can access its own files.

So I can simply copy the error page html to the function's directory, so it's deployed with the function and then return the error page with:

return open('404.html').read(), 404

Of course, you want to store the html into a variable, so it's not read each time a 404 error is sent.