NuxtN
Nuxt9mo ago
4 replies
Mirage

How to get asset URLs in api event handlers?

I'm trying to dynamically retrieve the URL of some assets using an api endpoint. Something similar to this:


export default defineEventHandler(async (event) => {

  // ...
  
  const coverUrl = (await import('~/assets/media/video-cover.mp4')).default;

  // ...

  return {
    coverUrl,
  }
})


However, that results in the following error:

Cannot find module '~/assets/media/video-cover.mp4' or its corresponding type declarations. ts(2307)


And just to be sure that the file is referenced correctly, the following works in
.vue
components:


<script setup lang="ts">
// ...

const coverUrl = (await import('~/assets/skirk.info/media/video-cover.mp4')).default

// ...
</script>
<template>
</template>
Was this page helpful?