Leaf MVC: `assets()` function behaves differently and breaks in production
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)
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/