leaf icon indicating copy to clipboard operation
leaf copied to clipboard

Leaf MVC: `assets()` function behaves differently and breaks in production

Open reinhart1010 opened this issue 1 year ago • 1 comments

Describe the bug At least in Leaf 3, the assets() function (used to get the absolute URL path for asset files) behaves differently between leaf serve and production (LiteSpeed Enterprise).

To Reproduce The Leaf MVC starter template (obtainable from leaf create project-name --mvc --v3) already contains a CSS <link rel="stylesheet"> declaration referring to a dynamically-generated path using the assets('css/styles.css') function. When trying to run the app using leaf serve, the web app styles loaded correctly, rendering the CSS tag as:

<link rel="stylesheet" href="/assets/css/styles.css">

However, when trying to deploy the app to production (using LiteSpeed Enterprise Server, and possibly reproducible in OpenLiteSpeed and Apache) when the website's root points to the public/ folder, the web server renders the style declaration as:

<link rel="stylesheet" href="/public/assets/css/styles.css">

Breaking the overall external CSS and JS paths.

This is reproducible in:

  • Leaf 3.3
  • PHP 8.3.0
  • macOS 14.2.1 (Sonoma)

reinhart1010 avatar Feb 18 '24 18:02 reinhart1010

I am getting a somewhat similar error... I created a new Leaf 3 MVC app, and when I run leaf serve the assets can only be referenced on /public/assets/... due to the combination of .htaccess and index.php files.

The following works as expected:

php -S localhost:8000 -t public/

JensRoland avatar Feb 21 '24 20:02 JensRoland