CDN question / problem with documentation

This is what it says here: http://galaxy-guide.meteor.com/cdn.html

If you have static assets such as images used in your templates (for example ) that you would also like to have cached by the CDN, you’ll need to include the CDN prefix and g_app_v query parameter in the image tag too. Combined with the previous example, the image would tag become <img src="https://d12345678.cloudfront.com/foo.png?_g_app_v_={process.env.GALAXY_APP_VERSION_ID}" />. We recommend you create a helper that does this for you only in production.

But process.env.GALAXY_APP_VERSION_ID isn’t available on the client, so this is a mistake right? How should this be handled?

1 Like

Anything in the public folder when you upload to galaxy will be automatically served by CloudFront after you config it. This should also serve your JS/CSS from there as well as images in your public folder.

Anything else, like when a user uploads their avatar to S3, you will need to do something like this on insert:

const S3_URL = 'https://mydomain.s3.amazonaws.com/'
const CDN_URL = 'https://5555555555.cloudfront.net'
const uploader = new Slingshot.Upload(uploadType, metaContext);

uploader.send(fileToUpload, function (error, downloadUrl) {
   let cleanUrl = downloadUrl.replace(S3_URL, CDN_URL);
   Meteor.call('saveS3ImageUrl', cleanUrl)
});

I don’t think you do need to do it for things like avatars with Galaxy.

Cloudfront will grab the image by itself.

You can read about it in the Meteor docs.

In any case these other items are not what I’m worried about. And again,
I’m not using Galaxy. The reason I asked this is for a non Galaxy solution.

I’m talking about where you are storing an S3 URL on a user’s mongoDB record. I’m not sure you’ll get that asset from cloudfront if the URL is for S3 (as it is when slingshot first returns it). You can probably setup a rule or behavior on S3/CloudFront, but I’m not sure it works out of the box?

Didn’t realize you weren’t using galaxy, your question was referencing the galaxy guide and setup with galaxy.

Apologies. I didn’t realise what question this was an answer to. My bad. I asked another question related to CDN in the last few days, but I see now this was in response to a question from 2 months ago.

Thanks for the help