directus / gatsby-source-directus

Source plugin for pulling data into Gatsby from a Directus API.
11 stars 12 forks source link

Solves #31 #32

Closed jbogdani closed 1 year ago

jbogdani commented 1 year ago

Fixes the missing slash dividing the base URL from the asset. The bug emerges when Directus is installed in a subdirectory.

rijkvanzanten commented 1 year ago

Thanks @jbogdani! Does this create the opposite problem for people including the trailing slash? F.e. example.com/ turning into example.com//assets and/or example.com/test/ to example.com/test//assets

jbogdani commented 1 year ago

Hello, I don't think so, because in l.176 the slash is being removed in the initialisation of basePath, if present:

const basePath = baseUrl.pathname.endsWith('/') ? baseUrl.pathname.slice(0, -1) : baseUrl.pathname;
rijkvanzanten commented 1 year ago

That's just for the /graphql endpoint though 🤔 I think we might want to make the changed line (93) a bit smarter by making sure the final URL is correct. It might make more sense to use the URL() constructor there as well

jbogdani commented 1 year ago

Yes, you are right. I didn't notice that plugin.url is using baseUrl and not basePath that is already cleaned up. What if we change l. 93 to something like:

const fileUrl = `${plugin.url}${plugin.url.endsWith('/') ? '' : '/'}assets/${file.id}`;

This is basically how basePath is defined in l.176.

If it makes sense to you I can update the patch.

rijkvanzanten commented 1 year ago

Lets do that! Thanks @jbogdani 🙌🏻

rijkvanzanten commented 1 year ago

This is released under 9.16.2