-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathroutes.js
57 lines (48 loc) · 1.85 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
import { Router } from '@edgio/core'
import getPrerenderRequests from './getPrerenderRequests'
import { isProductionBuild } from '@edgio/core/environment'
import { API_CACHE_HANDLER, EDGE_CACHE_HANDLER, IMAGE_CACHE_HANDLER } from './cache'
const router = new Router()
// Regex to catch multiple hostnames
// Any deployment will have a L0 permalink
// Don't allow Google bot to crawl it, read more on:
// https://docs.edgio.co/guides/cookbook#blocking-search-engine-crawlers
router.noIndexPermalink()
// Pre-render the static home page
// By pre-rendering, once the project is deployed
// the set of links are visited to warm the cache
// for future visits (expected to be the first view for real users)
// More on static prerendering: https://docs.edgio.co/guides/static_prerendering
router.prerender(getPrerenderRequests)
// Serve the old Edgio predefined routes by the latest prefix
router.match('/__xdn__/:path*', ({ redirect }) => {
redirect('/__edgio__/:path*', 301)
})
// API (Any backend) caching
router.match('/l0-api/:path*', API_CACHE_HANDLER)
// Image caching
router.match('/l0-opt', IMAGE_CACHE_HANDLER)
// Service Worker
router.match('/service-worker.js', ({ serviceWorker }) => {
serviceWorker('dist/service-worker.js')
})
// Only compiled with 0 build / 0 deploy
if (isProductionBuild()) {
// Cache but not in 0 dev mode
router.match('/', EDGE_CACHE_HANDLER)
router.match('/about', EDGE_CACHE_HANDLER)
router.match('/commerce', EDGE_CACHE_HANDLER)
router.match('/product/:path', EDGE_CACHE_HANDLER)
router.match('/commerce/:path', EDGE_CACHE_HANDLER)
// Serve all the files under dist folder as assets
router.static('dist')
// Serve rest of the routes via index.html
router.fallback(({ serveStatic }) => {
serveStatic('dist/index.html')
})
} else {
router.fallback(({ renderWithApp }) => {
renderWithApp()
})
}
export default router