-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.js
53 lines (51 loc) · 1.46 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
// This file was automatically added by xdn deploy.
// You should commit this file to source control.
const { Router } = require('@xdn/core/router')
const { nextRoutes, renderNextPage } = require('@xdn/next')
const router = new Router()
.match('/service-worker.js', ({ serviceWorker }) => {
serviceWorker('.next/static/service-worker.js')
})
.match('/missing-file', ({ serveStatic }) => {
serveStatic('path/that/does/not/exist.html', {
onNotFound: async () => {
await serveStatic(`.next/serverless/pages/404.html`, {
statusCode: 404,
statusMessage: 'Not Found',
})
},
})
})
.match('/missing-files/:path*', ({ serveStatic }) => {
serveStatic('path/that/does/not/exist/:path*.html', {
onNotFound: async () => {
await serveStatic(`.next/serverless/pages/404.html`, {
statusCode: 404,
statusMessage: 'Not Found',
})
},
})
})
.match('/_next/data/:build/p/:id.json', ({ cache }) => {
cache({
edge: {
maxAgeSeconds: 60 * 60 * 24,
},
browser: {
serviceWorkerSeconds: 60 * 60,
},
})
})
.get('/sale', (res) => {
renderNextPage('/p/[productId]', res, { productId: '1' })
})
.get('/compute', ({ compute, send }) => {
compute((req, res) => {
send(JSON.stringify({ query: req.query }))
})
})
.use(nextRoutes)
.fallback((res) => {
renderNextPage('fallback', res)
})
module.exports = router