Search code examples
apostrophe-cms

CSS and JS assets not being found when deploying Apostrophe CSM to Heroku


I'm following the HOWTO on deploying to Heroku: https://docs.apostrophecms.org/apostrophe/tutorials/howtos/deploying-apostrophe-in-the-cloud-with-heroku

I'm deviating from the HOWTO a bit since I'm using Heroku's mLab add-on to handle my Mongo. Also, I skipped the S3 set up for now, since I just want to get the thing up a running. I'm not sure if that's super important to the assets getting delievered appropriately.

I've completed the following from the HOWTO:

  • Created a project in Heroku
  • Added it to my git repo as heroku as a remote
  • Added mLab add-on and created a database and add the environment var pointing to that database uri.
  • Added environment vars for APOS_BUNDLE=1 and APOS_MINIFY=1
  • Added the heroku-release-scripts executable in the /scripts directory as well as the Procfile.

Here is the code from my ./scripts/heroku-release-scripts

#!/bin/bash

node app apostrophe:generation
node app apostrophe-migrations:migrate

Here is the Procfile

web: node app
release: ./scripts/heroku-release-tasks

One thing of note; If I look at the paths to my CSS and JS assets, it see something like this"

https://van-biema-partners.herokuapp.com/uploads/assets/ck0fmqn3i00050uuck7exy3v2/apos-minified/anon-ck0fmqn3i00050uuck7exy3v2.js

I'm not sure if that's correct, but maybe it is...

EDIT

Copy the above URL and remove out the '/uploads/assets/ck0fmqn3i00050uuck7exy3v2' part, I can see the CSS and JS. Not sure what's going on with the pathing, but that seems to be where the issue is, but I have no idea how to correct that. https://van-biema-partners.herokuapp.com/apos-minified/anon-ck0fmqn3i00050uuck7exy3v2.css


Solution

  • The issue is that the new, simplified APOS_BUNDLE=1 functionality strictly requires that you have a persistent uploadfs back end — in other words, it requires that you set up S3, even to be successful with asset URLs.

    Since this is in any case required for media uploads to work, I've fixed the documentation you read to address this requirement. I also removed a confusing leftover section about the --sync-to-uploadfs option, which is not required anymore to copy assets to S3; that is part of what led the confusing impression that S3 might not be mandatory.

    (Strictly speaking it does not have to be Amazon S3. In addition to supporting alternative S3 implementations, Apostrophe's uploadfs module also supports Azure blob storage and Google's cloud storage. The uploadfs documentation has more on that topic. What is truly a requirement is somewhere other than the heroku temporary filesystem to store things, because those are not persistent, nor are the same files visible to all dynos.)