Heroku, Grails: Missing resources if using multiple web dynos

后端 未结 3 1822
Happy的楠姐
Happy的楠姐 2021-01-23 04:54

I have created grails application and uploaded it in heroku.
If I use \'heroku scale web=1\' everything looks OK. But if I run \'heroku scale web=2\', some

3条回答
  •  别那么骄傲
    2021-01-23 05:20

    I had similar issues with image files that cannot be directly defined in ApplicationResources.groovy. I found a workaround for this one, though:

    Add a CSS file to ApplicationResources.groovy that has multiple class definitions for all the assets you need to load like this:

    .asset1 {
      background: url('path/to/image1.png');
    }
    .asset2 {
      background: url('path/to/image2.png');
    }
    .asset3 {
      background: url('path/to/image3.png');
    }
    ...
    

    And in ApplicationResources.groovy define the following:

    modules = {
        ...
        myModule {
            resource url: 'path/to/assets.css'
        }
        ...
    }
    

    Now the Resources plugin has already those paths ready for the images when the module that contains the CSS file is loaded from a GSP view, or if the images are referenced dynamically from JavaScript etc.

    Rather hacky but it works. Tested this in Heroku with 2 dynos.

提交回复
热议问题