Ability to read assets from public folder
Describe the feature
Would love to be able to get access to the assets variable that is created on build
For example:
const assets = {
"/success.html": {
"type": "text/html; charset=utf-8",
"etag": "\"7-i5KKyIzUGAhxNMutZtRIycH0cTo\"",
"mtime": "2025-10-27T22:40:48.992Z",
"size": 7,
"path": "../public/success.html"
}
};
What I'm dreaming of is being able to do something like this:
const fileContents = await useStorage('public:server').getItemRaw('success.html')
const meta = await useStorage('public:server').getMeta('success.html')
// Do some stuff with file...
setResponseHeader(event, 'content-type', meta.type)
return fileContents
I can of course do something similar with custom server assets but then I need to figure out the content type header on my own, feels like the all data is right there I just can't get access to it. Another option would be to export readAsset for end users. Thoughts?
Additional information
- [x] Would you be willing to help implement this feature?
Seems like I can do this in production, however it doesn't work during in development, feels sketchy though.
import { getPublicAssetMeta, readAsset } from '#nitro-internal-virtual/public-assets';
import assets from '#nitro-internal-virtual/public-assets-data'
export default defineEventHandler(async (event) => {
setResponseHeader(event, 'content-type', assets['/success.html'].type);
return readAsset('/success.html');
});
Another work around would be to call for the resource using $fetch. I'm cuirous if I call for resources in the public folder using $fetch, does unenv still apply? Or will it hit the network layer?