-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.js
42 lines (41 loc) · 1.32 KB
/
routes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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('/', ({ cache }) => {
cache({
edge: {
maxAgeSeconds: 60 * 60 * 24 * 365,
},
})
})
.get('/blogs/:username', ({ serveStatic, cache, renderWithApp }) => {
cache({
edge: {
maxAgeSeconds: 60 * 60 * 24 * 365, // keep the incrementally generated page for a year
staleWhileRevalidateSeconds: 1, // revalidate the data on page every second
},
browser: false,
})
serveStatic('dist/blogs/:username.html', {
// When the user requests a page that is not already statically rendered, fall back to SSR.
onNotFound: () => renderWithApp(),
})
})
.get('/api/blogs/:username.json', ({ serveStatic, cache, renderWithApp }) => {
cache({
edge: {
maxAgeSeconds: 60 * 60 * 24, // cache at the edge for 24 hours
},
})
serveStatic('dist/blogs/:username.json', {
// When the user requests data that is not already statically rendered, fall back to SSR.
onNotFound: () => renderWithApp(),
})
})
.use(nuxtRoutes)
.fallback(({ redirect }) => {
return redirect('/error')
})