utomic-media / directus-extension-field-actions

Add advanced link & copy functionalities to your directus fields. Supports interfaces as well as displays.
GNU General Public License v3.0
98 stars 10 forks source link

Feature Request: Allow using `PUBLIC_URL` as a base URL #16

Closed nobleach closed 1 year ago

nobleach commented 1 year ago

Currently I use Directus in several environments. What would be really useful is if this plugin could read the PUBLIC_URL and use that as a base so regardless of environment, I could just enter a URI and link/copy buttons could be "environment aware".

For example, if my preview url is http://localhost:8055/some/page anyone, regardless of environment will get the wrong link. If instead I set the link URL as /some/page. The PUBLIC_URL could be http://staging.example.com and the full preview URL would end up http://staging.example.com/some/page.

Dominic-Marcelino commented 1 year ago

Just to be sure to fully understand your request: You host directus + a custom frontend under the same URL, store some slugs in your fields and want to be able to dynamically link to {PUBLIC_URL}/{FIELD_VALUE}?

This will be partially supported via #3 Not sure though if we'll include dynamic variables, as in most cases directus and the frontend are hosted seperately and exposing the env vars to the frontend needs to be done carefully. Not sure if we can rely on FLOWS_ENV_ALLOW_LIST though

nobleach commented 1 year ago

Yeah you've gotten me thinking. PUBLIC_URL is the URL for the directus interface. That's not at all useful for me or most people. Perhaps a PREVIEW_BASE_URL is more useful. The dynamic field value would be extremely useful though. Being able to choose one record to hydrate a view is what I'm trying to achieve.

My apologies for missing issue #3

BenoitAverty commented 1 year ago

Hello, There is a "project url" setting that would fit the use case better. In my case it's exactly what I need :)

directus is hosted at directus.myproject.com, and the frontend itself is at www.myproject.com. The projet url setting is set to www.myproject.com (which makes it accessible from the directus logo in the top-left of the app), and my links are relative to that, so I would like to have a checkbox to enable this option.

For example, "Use Project URL as base for relative links".

This could be complementary to #3 because the public url is almost always an absolute url. So you could prepend the prefix, and then if the result is still a relative url prepend the public URL.

This setting seems to be accessible from the settings store (useSettingsStore)

If you're OK with this proposal, I'd be glad to try and submit a PR.