Repository navigation
Description
Environment
stackblitz with "nitro": "npm:nitro-nightly@latest"
Reproduction
Describe the bug
With the following config nitro config with publicAssets and maxAge:
export default defineNitroConfig({
srcDir: 'server',
publicAssets: [
// maxAge at root doesn't work for any presets?
{
dir: './client/',
baseURL: '/',
maxAge: 10,
},
// maxAge anywhere doesn't work for node-server preset?
{
dir: './client/nested/',
baseURL: '/nested/',
maxAge: 20,
},
],
});and building with node-server preset,
NITRO_PRESET=node-server nitro build
node .output/server/index.mjsneither of asset response includes cache-control.
curl -v http://127.0.0.1:3000/asset1.txt
curl -v http://127.0.0.1:3000/nested/asset2.txtBuilding with vercel preset NITRO_PRESET=vercel nitro build, it generates a following .vercel/output/config.json, which I'm not sure where max-age=31536000 is coming from and whether this is working intended.
{
"version": 3,
"overrides": {},
"routes": [
{
"headers": {
"cache-control": "public, max-age=20, immutable"
},
"src": "/nested/(.*)"
},
{
"src": "/nested(.*)",
"headers": {
"cache-control": "public,max-age=31536000,immutable"
},
"continue": true
},
{
"handle": "filesystem"
},
{
"src": "/(.*)",
"dest": "/__fallback"
}
]
}Additional context
One question: I noticed Nitro has routeRules which allows custom headers. I haven't tried, but is routeRoles preferred over nesting publicAssets like above?
Personally root assets not having cache-control seems fine, but being able to add cache-control only for some directory inside should work (at least either via publicAssets or routeRules).
I think this is the same issue I'm seeing in #3586 with the default node-server preset.
Activity
pi0 commentedon Sep 24, 2025
Thanks for the issue. In fact Nitro extends route rules (as single source of trust) from public assets (src).
Note: Base URL of
/is considered a "fall though" (because it can overlap with other routes therefore we don't have long term caching for those assets unless clearly prefixed with something like/clientor/_nuxt, etc)There is a chance we regressed this behavior in recent v3 changes. I will investigate more.
pi0 commentedon Sep 24, 2025
Found regression, after compiled routing (#3575) route rules were being applied after global middleware (serve static was one of them) therefore missing additional headers. 9fe8cd4 fixes is.
hi-ogawa commentedon Sep 25, 2025
Thanks for the pointer. That's good to know 🙏 Yes, the root fall through makes sense and my repro above with
maxAgewas for artificial purpose. I just wanted to confirm the behavior.For vercel routes, it generated two more
routeswithmax-age=20andmax-age=31536000. Is this expected?pi0x commentedon Sep 7, 2026
Answering the leftover question about the second Vercel route: no, that was a bug. The Vercel preset emitted its own
cache-controlroute for every non-fallthroughpublicAssetsentry withmax-age=31536000hardcoded, ignoring themaxAgeyou set, so you got two routes for the same directory.Fixed in be23b43 — the header is now built from the directory's
maxAge(one year only when unset) and is skipped entirely when a route rule already setcache-control. Building your config on currentmainnow emits just themax-age=20route for/nested/(.*), and node-server sendscache-control: public, max-age=20, immutableon/nested/asset2.txt. Root assets still get nothing, which is the fall-through behaviour pi0 described.Posted by an AI triage agent on behalf of a maintainer.