Custom media and assets URLs

Hi all

I’m struggling with putting the media and assets urls behind a common prefix (/cms in my case). The reason is I’m running an SPA on the same domain, and media is already used by that. FWIW, I’m also using the zero one template, so much of the configuration is done by that.

I’m doing this in index.php:

$kirby = new Kirby([
    'urls' => [
        'media' => '/cms/media',
        'assets' => '/cms/assets',
    ]
]);

which does the rendering part. My question is now, how to get the serving part right. I’m aware, with a reverse proxy, I can do it. Is there a way to do it within kirby? I’d prefer the latter, since it’d make the setup simpler.

I’ve gotten as far as this:

'routes' => [
    [
      'pattern' => 'cms/media/(:all)',
      'action' => function ($path) { 
         return kirby()->router()->call('media/' . $path);
      }
    ],
]

But, alas, that doesn’t work.

At the same time, there still are many requests going directly to /assets/*, why?

Would it be a better idea to just move CMS calls to a separate subdomain? If I understand this correctly, that is directly supported.

You can change of the names of the folders in the config, i think thats wha you need.

I’m sorry if I wasn’t clear enough, the folders are fine, I want to serve them from another path.

So

https://mydomain.com/assets/hero.jpg => https://mydomain.com/cms/assets/hero.jpg

While having the same, default, folder structure.

I was hoping it to be possible (because of the urls) option to Kirby, in the example (Custom URL setup | Kirby CMS):

$kirby = new Kirby([
    'urls' => [
        'index'  => 'https://getkirby.com',
        'media'  => 'https://media.getkirby.com',
        'assets' => 'https://assets.getkirby.com',
    ]
]);

which I’ve tried to use as above.

This expects a url, not a path, so

$kirby = new Kirby([
    'urls' => [
        'media' => 'https://yourdomain.com/cms/media',
//etc.
    ]
]);

Thank you for the reply.

Yes, that helps!

Now I find out that the template I’m using has lots of these in their code:

css('/assets/app/dist/css/uikit.app.min.css') 

… which then don’t get mapped to the correct location. I guess it would have to be something like this:

$kirby->url('assets') . '/app/dist/css/uikit.app.min.css'

Right?

Yes, from a quick look at the underlying code, that seems to be necessary unless you overwrite the css component.

I’ve contacted the author, thank you so much for looking.

I also got problems with panel though. Some files (index.css and panel.css) seem to resolve fine, whereas others (the minified stuff like vendor.min.js, plugins.js) 404.

Please note that this is not a failure of the theme, the original code is the correct way to use the css() helper, as documented in our docs.

It will just not work with what you are planning to do.

Now I’m confused, if not as described in Custom URL setup, what then is the canonical way to modify those URLs in a way that should be supported by plugins?

Also, I’m not dead-set on this, and open to suggestions. Would it be easier/more canonical to use a custom domain for assets etc. as well as panel (cms.mydomain.com)?

My problem is that media/ clashes with a path on the apex domain which is used by a django app.