JonasKruckenberg / imagetools

Load and transform images using a toolbox :toolbox: of custom import directives!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Respect Vite's "server.origin" option.

pavlo-tk opened this issue · comments

Hello,

I noticed that while running Vite's dev server, URLs for images generated by vite-imagetools are relative (i.e. /@imagetools/c224b1fb8dcc644a0adf403cda4d43b3390bbf1f). For the most part, this is fine, but as soon as you're integrating with the backend, these relative paths break images.

Vite has server.origin option specifically for these cases: https://vitejs.dev/config/server-options.html#server-origin
It's also explained in the "Backend Integration" section in their docs: https://vitejs.dev/guide/backend-integration.html:

In order to properly serve assets, you have two options:

1. Make sure the server is configured to proxy static assets requests to the Vite server
2. Set `server.origin` so that generated asset URLs will be resolved using the back-end server URL instead of a relative path
This is needed for assets such as images to load properly.

Right now the only way to work with vite-imagetools while the app is integrated with any backend is to rewrite URLs server-side (Apache, NGINX).

It would be nice if vite-imagetools would respect server.origin option and we could stop hardcoding those rewrite rules.

Created a PR for this:
#690