-
Notifications
You must be signed in to change notification settings - Fork 1
/
routes.js
57 lines (51 loc) · 1.45 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
57
const { Router } = require("@layer0/core/router");
export const API_CACHE_HANDLER = ({
removeUpstreamResponseHeader,
cache,
proxy,
}) => {
removeUpstreamResponseHeader("cache-control");
cache({
browser: {
maxAgeSeconds: 0,
serviceWorkerSeconds: 60 * 60 * 24,
},
edge: {
maxAgeSeconds: 60 * 60 * 24 * 365 * 10,
staleWhileRevalidateSeconds: 60 * 60 * 24,
},
});
proxy("api");
};
const ONE_HOUR = 60 * 60;
const ONE_DAY = 24 * ONE_HOUR;
const ONE_YEAR = 365 * ONE_DAY;
const edgeOnly = {
browser: false,
edge: { maxAgeSeconds: ONE_YEAR },
};
const edgeAndBrowser = {
browser: { maxAgeSeconds: ONE_YEAR },
edge: { maxAgeSeconds: ONE_YEAR },
};
module.exports = new Router()
.prerender([{ path: "/" }])
// match routes for js/css resources and serve the static files
.match("/static/:path*", ({ serveStatic, cache }) => {
cache(edgeAndBrowser);
serveStatic("build/static/:path*");
})
// match client-side routes that aren't a static asset
// and serve the app shell. client-side router will
// handle the route once it is rendered
.match("/:path*/:file([^\\.]+|)", ({ appShell, cache }) => {
cache(edgeOnly);
appShell("build/index.html");
})
// match other assets such as favicon, manifest.json, etc
.match("/:path*", ({ serveStatic, cache }) => {
cache(edgeOnly);
serveStatic("build/:path*");
})
// send any unmatched request to serve the static index.html
.fallback(({ serveStatic }) => serveStatic("build/index.html"));