Aggregated CSS/JS not found with some file-path configurations

Created on 11 August 2023, over 1 year ago
Updated 14 November 2023, over 1 year ago

Problem/Motivation

Uploaded and generated files can be stored outside the Drupal docroot. This can provide performance benefits and security benefits (for example, having the executable code stored on a read-only file-system).

An example structure may look as follows:

var
├─ www
   ├─ app
   │  ├─ docroot
   │     ├─ index.php
   │     ├─ ...
   ├─ data
      ├─ files
      ├─ files-private

This datastructure is supported in settings with parameters such as this:

$host = !empty($_SERVER['HTTPS'])
  ? 'https://' . $_SERVER['HTTP_HOST']
  : 'http://'  . $_SERVER['HTTP_HOST'];

$settings['file_public_base_url']  = "{$host}/{$site_path}/files";
$settings['file_public_path']      = "/var/www/data/files";
$settings['file_private_path']     = "/var/www/data/files-private";

When this structure is used, and "Aggregate CSS/JS" is enabled, the styles and JS are not available.

Cause

The asset routing makes assumptions about directory structure and URL structure which do not always hold true.

public function routes(): array {
  $routes = [];
  // Generate assets. If clean URLs are disabled image derivatives will always
  // be served through the routing system. If clean URLs are enabled and the
  // image derivative already exists, PHP will be bypassed.
  $directory_path = $this->streamWrapperManager->getViaScheme('assets')->getDirectoryPath();

With the configuration described above, the registered route path for CSS is /var/www/data/files/css/{$filename}.

Proposed resolution

Refactor the Asset APIs to align with the current behavior of the Public file structure.
Perhaps an additional settings option, $settings['file_asset_base_url'] would be appropriate.

Remaining tasks

- Evaluate solution options
- Add tests

Release notes snippet

🐛 Bug report
Status

Needs work

Version

10.1

Component
Asset library 

Last updated 2 days ago

No maintainer
Created by

🇬🇧United Kingdom manarth

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024