Skip to content

Instantly share code, notes, and snippets.

@rishi-raj-jain
Last active September 9, 2021 10:29
Show Gist options
  • Save rishi-raj-jain/a2478942c3fa5fa507260fabcd95c68f to your computer and use it in GitHub Desktop.
Save rishi-raj-jain/a2478942c3fa5fa507260fabcd95c68f to your computer and use it in GitHub Desktop.
// 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