Text fields: embedded image URLs should be absolute?
yann-yinn opened this issue · 5 comments
Hey, i love Reservoir UI, nice to see JSON API so easily from the back, i was able to build really quickly a front-end with Vue.js, great job !
My issue : when i display my content from my Nuxt.js front-end, images url are broken because they are relative to my client server :
src="/sites/default/files/inline-images/Capture%20d%E2%80%99e%CC%81cran%202017-06-14%20a%CC%80%2021.06.18.png"
Expected behavior is an absolute url to Reservoir Server on rendered content. This was https://www.drupal.org/project/pathologic job when using D7
PS : looks forward to see GraphQL implemented, that would give D8 a big advantage in comparison to other back-end solutions
Wonderful! Glad to hear you were able to very quickly get started 👍
Reservoir (Drupal) is intentionally providing root-relative file URLs: so that you can easily prefix it with whichever host you're letting serve static files. Many will want to use a CDN. Others will want to set up Varnish or nginx. And more importantly: to prevent problems when switching from your dev environment to your prod environment.
If we'd be returning absolute URLs, and you would be using those directly, then it'd be trivial to figure out the back end's URL. You probably don't want to expose Reservoir to the world.
If you do want to use Reservoir's web server directly (which makes total sense for development), then the same base URL that you use to talk to Reservoir can also be used to access static files. In production, you'd change this to a CDN base URL.
Thoughts?
Oh, I thought you were referring to a file URL for the "Image" field! But you're referring to a file URL embedded in the rich text. That's … a very good point.
I can think of multiple approaches:
- in your client, you can parse this HTML, then do
querySelectorAll('img[data-entity-type=file]')
to get all relevantimg
tags, and prefix theirsrc
- Reservoir could remove the ability to have embedded images
- Reservoir could add a filter with a "static file URL" setting that's exposed in Reservoir's UI, and then combined with https://www.drupal.org/node/2626924, there would not just be
field_body[value]
, but alsofield_body[processed]
, which would then contain the absolute file URL
Thoughts?
I would say that it does not makes much sense from a client-side perspective to receive a rendered body with "broken" links. This add extra works on each client ( we may have several clients pointing to the same reservoir ) to fix those urls. This is not hard but it has to be replicated and maintained on all clients.
So I would expect an option in reservoir to send processed urls. This allows to configure CDN from reservoir (or to simply use reservoir server url), and reservoir is able to propagate right urls to all clients.
I dont see the issue with "then it'd be trivial to figure out the back end's URL", my XHR requests reveals it anyway
Most people want their backends to have the smallest exposure possible. In this case (Reservoir) that would be done by only allowing requests to /jsonapi/*
URLs from public IP ranges.