mootoday / ghost-v3-google-cloud-storage

A Google Cloud Storage adapter for Ghost v3 (www.ghost.org).
13 stars 7 forks source link

Appending `assetDomain` to beginning of URL when fetching favicon #1

Open devinowen opened 4 years ago

devinowen commented 4 years ago

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 commented 4 years ago

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:

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago

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

markmssd commented 4 years ago

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">