Skip to content

Commit

Permalink
fix: update cache storage for pre-rendering phase
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux committed Oct 13, 2024
1 parent d05aa74 commit 4a24a47
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions playground/app/pages/cached.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script setup>
const { data } = await useFetch('/api/cached')
</script>

<template>
<pre>{{ data }}</pre>
</template>
4 changes: 4 additions & 0 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export default defineNuxtConfig({
// projectUrl: ({ branch }) => branch === 'main' ? 'https://playground.nuxt.dev' : `https://${encodeHost(branch).replace(/\//g, '-')}.playground-to39.pages.dev`
},

routeRules: {
'/cached': { prerender: true }
},

basicAuth: {
enabled: process.env.NODE_ENV === 'production',
allowedRoutes: ['/api/_hub/'],
Expand Down
10 changes: 10 additions & 0 deletions src/features.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { execSync } from 'node:child_process'
import type { Nuxt } from '@nuxt/schema'
import { join } from 'pathe'
import { logger, addImportsDir, addServerImportsDir, addServerScanDir, createResolver } from '@nuxt/kit'
import { joinURL } from 'ufo'
import { defu } from 'defu'
Expand Down Expand Up @@ -165,6 +166,15 @@ export async function setupCache(nuxt: Nuxt) {
}
}
})
nuxt.hooks.hook('nitro:init', (nitro) => {
nitro.hooks.hook('prerender:config', (config) => {
config.devStorage ||= {}
config.devStorage.cache = {
driver: 'fs',
base: join(nuxt.options.rootDir, '.data/cache')
}
})
})

// Add Server scanning
addServerScanDir(resolve('./runtime/cache/server'))
Expand Down

0 comments on commit 4a24a47

Please sign in to comment.