Last active
September 9, 2021 10:29
-
-
Save rishi-raj-jain/a2478942c3fa5fa507260fabcd95c68f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This file was added by layer0 init. | |
// You should commit this file to source control. | |
const { Router } = require("@layer0/core/router") | |
const { nuxtRoutes } = require("@layer0/nuxt") | |
module.exports = new Router() | |
.match("/service-worker.js", ({ serviceWorker }) => { | |
serviceWorker(".nuxt/dist/client/service-worker.js"); | |
}) | |
.get("/some-route/:slug", ({ cache }) => { | |
cache({ | |
edge: { | |
maxAgeSeconds: 60 * 60 * 24 * 365, // keep the incrementally generated page for a year | |
}, | |
browser: false, | |
}) | |
serveStatic('dist/some-route/:slug.html', { | |
// When the user requests a page that is not already statically rendered, fall back to SSR. | |
onNotFound: () => renderWithApp() | |
}) | |
}) | |
.get('/api/some-route/:slug.json', ({ serveStatic, cache, renderWithApp }) => { | |
cache({ | |
edge: { | |
maxAgeSeconds: 60 * 60 * 24, // cache at the edge for 24 hours | |
}, | |
}) | |
serveStatic('dist/some-route/:slug.json', { | |
// When the user requests data that is not already statically rendered, fall back to SSR. | |
onNotFound: () => renderWithApp(), | |
}) | |
}) | |
.use(nuxtRoutes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment