1

It seems like I finally figured how to setup Rails + Paperclip + AWS CDN + Heroku. Everything seems to be working. Both CSS and js files load from cdn, as well as images. Unfortunately sharing functionality is broken. Open graph can't parse image url. I assume it's because links are in this format https:////drex16ydhdd8s.cloudfront.net/...rest_of_url

Originally, long time ago, I've configured CDN link to be //drex16ydhdd8s.cloudfront.net. I understand I need to remove slashes in front of the link, make it drex16ydhdd8s.cloudfront.net instead.

The problem is, if I do it, Heroku gives me Application Error. (displays their static page) Logs don't display anything helpful, other than it seems it goes over memory limit pretty much immediately.

I've contacted Heroku support, but their response was

You should not need any slashes, it should just be a host name. (As seen in the documentation for config.action_controller.asset_host.) If removing the slashes causes errors, you'll want to debug those errors.

I tried to do it locally, everything seems to work as expected.

environments/production.rb

  config.action_controller.asset_host = ENV.fetch("ASSET_HOST", ENV.fetch("APPLICATION_HOST"))

  config.paperclip_defaults = {
    storage: :s3,
    s3_protocol: :https,
    s3_region: ENV["AWS_REGION"],
    url: ":s3_alias_url",
    path: "/:class/:attachment/:id_partition/:style/:filename",
    s3_host_alias: ENV.fetch("ASSET_HOST"),
    s3_credentials: {
      bucket: ENV["S3_BUCKET_NAME"],
      access_key_id: ENV["AWS_ACCESS_KEY_ID"],
      secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"]
    },
    default_url: "https://s3.amazonaws.com/ezpoisk/missing-small.png"
  }

env variable ASSET_HOST = //drex16ydhdd8s.cloudfront.net

on CDN I have 2 befaviors

  • /assets/* - that points to domain name
  • default (*) - that points to s3 bucket

Does anyone have any ideas?

AndreiMotinga
  • 1,024
  • 17
  • 24

1 Answers1

0

Solution. I had in production.rb config.assets.compile = true

I'm not strong on details here, I just remember that I made a note on this line to possibly remove it when switching to cdn. After digging through this answer I have decided to try it out. So I

  • removed the lined,
  • deployed,
  • all works fine.
  • Tried updating cdn link then.
  • At first, same issue persisted, url for some reason was /drex16ydhdd8s.cloudfront.net, but after few seconds it now seems to be all good.
AndreiMotinga
  • 1,024
  • 17
  • 24