-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.js
47 lines (46 loc) · 1.73 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
import { Router } from '@edgio/core'
import { reactCRARoutes } from '@edgio/react-cra'
export default new Router()
// API (Any backend) caching
.match('/l0-api/:path*', ({ removeUpstreamResponseHeader, cache, proxy }) => {
removeUpstreamResponseHeader('cache-control')
removeUpstreamResponseHeader('set-cookie')
cache({
edge: {
maxAgeSeconds: 60 * 60,
// Cache responses even if they contain cache-control: private header
// https://docs.edg.io/guides/caching#private
// https://docs.edg.io/docs/api/core/interfaces/_router_cacheoptions_.edgecacheoptions.html#forceprivatecaching
forcePrivateCaching: true,
},
browser: {
// Don't save the response in the browser
maxAgeSeconds: 0,
// Save the response in the browser via Edgio service worker
serviceWorkerSeconds: 60 * 60 * 24,
},
})
proxy('api', { path: ':path*' })
})
// Image caching
.match('/l0-opt', ({ removeUpstreamResponseHeader, cache, proxy }) => {
removeUpstreamResponseHeader('cache-control')
removeUpstreamResponseHeader('set-cookie')
cache({
edge: {
maxAgeSeconds: 60 * 60,
// Cache responses even if they contain cache-control: private header
// https://docs.edg.io/guides/caching#private
// https://docs.edg.io/docs/api/core/interfaces/_router_cacheoptions_.edgecacheoptions.html#forceprivatecaching
forcePrivateCaching: true,
},
browser: {
// Don't save the response in the browser
maxAgeSeconds: 0,
// Save the response in the browser via Edgio service worker
serviceWorkerSeconds: 60 * 60 * 24,
},
})
proxy('image', { path: '/' })
})
.use(reactCRARoutes)