Static files with Nuxt (Nitro) handler preset
When self-hosting Nuxt build, by default it uses
I wanted to add more logic around this, such as authorization headers, error handling, metrics tracking, and more. So I switch to
I went the simple route and simply added static serving on my own, from public directory.
This worked well, until I faced problem with
Notice I have images, and I want then cached for 6666 seconds.
When I build this as node-server, my
When I build for node-listener, they dont get served (shows index HTML instead). When I add my own static serving, it doesnt respect nitro routeRules, so headers dont get added.
---
What is recommended solution for this problem?
A) Is there a way to tell node-listener to also serve static files?
B) When serving static files on my own, are there any helpers to use to respect those nitro configurations?
node-server preset. This gives an entrypoint that runs on a port and serves website. All works well in this setup.I wanted to add more logic around this, such as authorization headers, error handling, metrics tracking, and more. So I switch to
node-listener preset, but static files stops working, like robots.txt in public directory.I went the simple route and simply added static serving on my own, from public directory.
This worked well, until I faced problem with
nitro configuration in nuxt.config.ts, for example this one:Notice I have images, and I want then cached for 6666 seconds.
When I build this as node-server, my
img/sample-3.png has correct cache control headers.When I build for node-listener, they dont get served (shows index HTML instead). When I add my own static serving, it doesnt respect nitro routeRules, so headers dont get added.
---
What is recommended solution for this problem?
A) Is there a way to tell node-listener to also serve static files?
B) When serving static files on my own, are there any helpers to use to respect those nitro configurations?
