Getting AssetBundle /static resources to generate urls with `baseUrl`


(jusdino) #1

I’m toying with a fork of a git repository that I found that dockerizes Humhub, a Yii2-based php app. I’m trying to get it to run behind a proxy, set under a subdirectory URL so http://proxy-host/humhub/ -> http://humhub-host/ works correctly.

My gut says that I’ve just miss-configured something based on my limited understanding of how a Yii app works.

I’ve gotten all the main page (pretty) urls to use the correct baseUrl, like /humhub/... and all of the /asset routes seem to be correct, like /humhub/asset/... but there are a number of /static routes that are not using the baseUrl the way I would expect (configuration details below) and, instead of generating a URL at /humhub/static/..., they are /static/.... I checked the resources that don’t seem to be using the baseUrl setting and they appear to all be from AssetBundle classes (an example below).

I know just enough about PHP to be laughed at by people who do know PHP and even less about Yii so I’m a bit out of my depth so far.

For Reference:
Here’s the full code I’m playing with:

The app source is here:

More Details:
I’ve confirmed that the baseUrl setting has been applied and I also added some code to common.php to get the urlManager and assetManager appropriately configured:

<?php
/**
 * This file provides to overwrite the default HumHub / Yii configuration by your local common (Console and Web) environments
 * @see http://www.yiiframework.com/doc-2.0/guide-concept-configurations.html
 * @see http://docs.humhub.org/admin-installation-configuration.html
 * @see http://docs.humhub.org/dev-environment.html
 */
return [
    'params' => [
        'enablePjax' => false
    ],
    'components' => [
        'urlManager' => [
            'class' => 'yii\web\UrlManager',
            'showScriptName' => false,
            'enablePrettyUrl' => true,
            'baseUrl' => 'http://localhost/humhub',
            'hostInfo' => 'http://localhost',
        ],
        'assetManager' => [
            'baseUrl' => 'http://localhost/humhub/assets',
        ],
    ]
];

I added a couple of quick functions to test aliases and configuration settings since I couldn’t think of a better way, and here’s what I saw:

/var/www/localhost/htdocs/protected # php yii installer/get-alias @web
http://localhost/humhub

/var/www/localhost/htdocs/protected # php yii installer/get-alias @web-static
http://localhost/humhub/static

/var/www/localhost/htdocs/protected # php yii installer/get-config baseUrl
http://localhost/humhub

MariaDB [humhub]> select * from setting where name='baseUrl';
+----+---------+-------------------------+-----------+
| id | name    | value                   | module_id |
+----+---------+-------------------------+-----------+
|  4 | baseUrl | http://localhost/humhub | base      |
+----+---------+-------------------------+-----------+
1 row in set (0.000 sec)

The functions I used are in the ExtendedInstallController class here (new users can only put two links, so link removed – find it under the jusdino git repo linked above under /humhub/protected/humhub/modules/installer/commands/ExtendedInstallController.php)

So, it sure looks like @web and @web-static are loading correctly and baseUrl looks right both in the database and loaded as a Yii setting. The URLs that are hitting my proxy without the /humhub/ sub-directory are for resources in AssetBundle classes like CoreAPIAsset.php (in the humhub repo under protected/humhub/assets/CoreApiAsset.php) but it looks to be setting it’s baseUrl correctly:

/**
* HumHub Core Api Asset
*/
class CoreApiAsset extends AssetBundle
{
    /**
     * @inheritdoc
     */
    public $basePath = '@webroot-static';

    /**
     * @inheritdoc
     */
    public $baseUrl = '@web-static';

    ...

    /**
     * @inheritdoc
     */
    public $js = [
        'js/humhub/legacy/jquery.loader.js',
        // All the resources that hit /static instead of /humhub/static
        ...
    ];

}

I can’t think of any other place to look unless there’s some other urlManager or assetManager like class out there that also has its own baseUrl setting that I’m missing or something.

Any guidance on this would be really appreciated because I feel like I must be going about this the wrong way.