-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.js
56 lines (55 loc) · 1.67 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const { BUILD_ID } = require('./BUILD_ID')
const { nuxtRoutes } = require('@edgio/nuxt')
const { Router } = require('@edgio/core/router')
// const IF_PRODUCTION = process.env.NODE_ENV === 'production'
module.exports = new Router()
.noIndexPermalink()
.match('/service-worker.js', ({ serviceWorker }) => {
serviceWorker('.nuxt/dist/client/service-worker.js')
})
.match('/manifest.js', ({ cache, serveStatic }) => {
cache({
edge: {
maxAgeSeconds: 60 * 60 * 24 * 365,
},
})
serveStatic(`dist/_nuxt/static/${BUILD_ID}/manifest.js`)
})
.match('/:path*/manifest.js', ({ cache, serveStatic }) => {
cache({
edge: {
maxAgeSeconds: 60 * 60 * 24 * 365,
},
})
serveStatic(`dist/_nuxt/static/${BUILD_ID}/manifest.js`)
})
.get('/', ({ cache }) => {
cache({
edge: {
maxAgeSeconds: 60 * 60 * 24 * 365,
},
})
})
.get('/blogs/:username', ({ /* serveStatic, */ cache, renderWithApp }) => {
cache({
edge: {
maxAgeSeconds: 2,
staleWhileRevalidateSeconds: 60, // serve stale responses for a minute until new content is fetched, in background a new request is looking for new content
},
browser: false,
})
// if (IF_PRODUCTION)
// serveStatic('dist/blogs/:username.html', {
// // When the user requests a page that is not already statically rendered, fall back to SSR.
// onNotFound: () => renderWithApp(),
// })
// else renderWithApp()
renderWithApp()
})
.get('/api/blogs/:username.json', ({ renderWithApp }) => {
renderWithApp()
})
.use(nuxtRoutes)
.fallback(({ redirect }) => {
return redirect('/error')
})