From a0cdcbebe0910764fe709c980adb53199ed357bc Mon Sep 17 00:00:00 2001
From: Remi  PLANEL <rplanel@pasteur.fr>
Date: Thu, 28 Sep 2023 15:05:52 +0200
Subject: [PATCH] Deal with baseUrl runtime config for url

---
 components/content/MolstarPdbePlugin.vue | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/components/content/MolstarPdbePlugin.vue b/components/content/MolstarPdbePlugin.vue
index 70822d08..5e40ebdf 100644
--- a/components/content/MolstarPdbePlugin.vue
+++ b/components/content/MolstarPdbePlugin.vue
@@ -1,9 +1,21 @@
 <script setup lang="ts">
+import { withTrailingSlash, withLeadingSlash, joinURL } from 'ufo'
+import { useRuntimeConfig, computed } from '#imports'
 export interface Props {
     height?: number
     dataUrl: string
 }
 
+const refinedDataUrl = computed(() => {
+    if (props.dataUrl?.startsWith('/') && !props.dataUrl.startsWith('//')) {
+        const _base = withLeadingSlash(withTrailingSlash(useRuntimeConfig().app.baseURL))
+        if (_base !== '/' && !props.dataUrl.startsWith(_base)) {
+            return joinURL(_base, props.dataUrl)
+        }
+    }
+    return props.dataUrl
+})
+
 const props = withDefaults(defineProps<Props>(), {
     height: 600,
 })
@@ -28,7 +40,7 @@ useHead({
 
 <template>
     <v-card flat color="transparent" :min-height="height" position="relative" class="my-3">
-        <pdbe-molstar :custom-data-url="dataUrl" custom-data-format="pdb" alphafold-view="true" landscape="true"
+        <pdbe-molstar :custom-data-url="refinedDataUrl" custom-data-format="pdb" alphafold-view="true" landscape="true"
             hide-expand-icon sequence-panel></pdbe-molstar>
     </v-card>
 </template>
-- 
GitLab