lhapaipai / symfony-vite-dev

Monorepo for symfony-vite development
https://symfony-vite.pentatrion.com
Other
22 stars 20 forks source link

Use Request::getUriForPath to build absolute URLs #13

Closed andyexeter closed 8 months ago

andyexeter commented 8 months ago

I noticed whilst looking into the issue discussed in #7 that the method to generate absolute URLs for assets when absolute_url is true was missing a few potential components in in the URL (port, base path etc).

For example, if a site was hosted at http://example.org:8080/subdirectory and we wanted to get an absolute URL for /build/foo.jpg, the current methods return:

http://example.org/build/foo.jpg

Which would result in a 404.

This PR updates the completeURL methods in ViteAssetVersionStrategy and EntrypointRenderer so that they use the getUriForPath method from Symfony's Request object. This builds the full URL including all required components and in the example above returns the following correct URL:

http://example.org:8080/subdirectory/build/foo.jpg
netlify[bot] commented 8 months ago

Deploy Preview for cosmic-bubblegum-aa631a canceled.

Name Link
Latest commit 77103b2bda15e456da42d360aac651b15c3497cc
Latest deploy log https://app.netlify.com/sites/cosmic-bubblegum-aa631a/deploys/65b0de1375e312000851bc1a
andyexeter commented 8 months ago

I'll fix the tests tomorrow :)

andyexeter commented 8 months ago

Tests are passing

lhapaipai commented 8 months ago

Thanks for your work @andyexeter ! you can find all this in version 6.3.4 ok, I'm going to bed...