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

Appending assetDomain to beginning of URL when fetching favicon #1

Open
devinowen opened this issue Nov 22, 2019 · 6 comments
Open

Comments

@devinowen
Copy link

Hey Mike! Hope you find this since the repo is blank :)

First off, thanks for making this adapter! It saved me when trying to set up Ghost on Google App Engine. Everything works great, except that trying to load the favicon.png file on article pages throws a 500. It looks like the location URL has the original assetDomain string appended to the beginning, so that it's trying to get the icon from a URL like this:

ASSET_DOMAIN/https://ASSET_DOMAIN.storage.googleapis.com/2019/11/logo.png

Instead of what it should be:

https://ASSET_DOMAIN.storage.googleapis.com/2019/11/logo.png

Any thoughts on how to fix this? I'd be happy to submit a PR if you can steer me in the right direction (and if the repo gets populated, obviously).

@mikenikles
Copy link
Collaborator

Hey Devin,

First of all, I pushed the source code earlier today 🎉!

For some reason, I didn't get an email notification, but luckily stopped by here and noticed your message.

I was able to reproduce your issue on my blog. This was also reported in the Ghost repo back in 2017. It was closed, but as we can tell it's still an issue - or I miss something.

Here's what I found:

  • The middleware calls serveFavicon() - Source
  • serveFavicon() gets the favicon path via getIconPath() - Source
  • getIconPath() loads the icon's path from the settings. I confirmed in the database this is the absolute URL to the icon. It then gets the local file storage path via getLocalFileStoragePath() - Source
  • getLocalFileStoragePath() doesn't seem to modify the icon path - Source
  • Which brings us back to the middleware where the GCS storage adapter is called with the invalid path value - Source

From what I can tell, the icon path comes straight from the database (where it is correct), gets passed through a few functions, but never modified before it's passed to the GCS storage adapter.

What am I missing 😄 ?!

@johngoggs
Copy link

Hi Devin,

I had this problem that I have just solved. I am not sure it will solve your problem, though.

TLDR; once you're using Mike's GCS package, delete you favicon from the Ghost Admin console, check the value for icon (under the settings table in your database) has cleared, reupload your favicon.

The issue for me was the same as Devin, but something was placing my storage bucket id in front of the full URL (ghost_content/https://cdn.url/favicon.png). I can only assume it was to do with using an old package on a newer version of Ghost.

Sorry, I can't solve your issue, but I believe it is due to Ghost not handling the favicon correctly with an older GCS package.

@devinowen
Copy link
Author

Hey @mikenikles and @meapleio thanks for looking into this. I tried deleting the favicon and re-uploading it but got the same result (on the latest version of Ghost).

Since Mike has confirmed that the image path is being stored correctly in the DB, it seems like the only place that could possibly be appending the bucket ID is in getLocalFileStoragePath(). I'll open an issue in TryGhost since it doesn't seem to us that the problem is in the storage adapter.

@johngoggs
Copy link

@devinowen I revisited this issue tonight, and I did come across it in my production environment :'(

I've installed a fresh Ghost install in Cloud Run & Cloud SQL, and I get the same issue. Because of this, I know it hasn't got anything to do with my production environment being old and full of garbage. This issue also occurs if you set the cdn variable.

I'll comment on your post over at TryGhost.

@devinowen
Copy link
Author

@meapleio thanks for taking a look! Hopefully this gets all sorted out in that other issue :)

@markmssd
Copy link

In the meantime until it gets resolved, here's my workaround, hopefully it can help some.

I have uploaded my favicon.png at the root of my Google Bucket, gave it public access, then
I've injected a <link rel="icon"> in the header through the admin dashboard as:

<link rel="icon" 
      type="image/png" 
      href="https://storage.googleapis.com/MY-BUCKET-ID/favicon.png">

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