-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
routes.ts
285 lines (284 loc) · 7.64 KB
/
routes.ts
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
// This is the config file for the web hosting and CDN
import { Router } from "@edgio/core/router";
import { nextRoutes } from "@edgio/next";
export default new Router()
// .always(({ setOrigin }) => {
// setOrigin("edgio_serverless");
// })
.use(nextRoutes) // automatically adds routes for all files under /pages
// Do not index dev sites
.match(
{
headers: {
host: /dev.coh3stats.com|preview.coh3stats.com/,
},
},
({ setResponseHeader }) => {
setResponseHeader("x-robots-tag", "noindex, nofollow, noarchive, noimageindex");
},
)
.match(
{
headers: {
host: /^www.coh3stats.com$/,
},
},
({ setResponseHeader, setResponseCode }) => {
// %{normalized_uri} => /path/to/resource?query=string
setResponseHeader("location", "https://coh3stats.com%{normalized_uri}");
setResponseCode(301);
},
)
// Do not access dev / preview sites for robots
.match(
{
path: "/robots.txt",
headers: {
host: /dev.coh3stats.com|preview.coh3stats.com/,
},
},
({ send, cache }) => {
send("User-agent: *\nDisallow: /", 200);
cache({
edge: {
maxAgeSeconds: 60 * 60 * 24,
staleWhileRevalidateSeconds: 60 * 60 * 24 * 7,
forcePrivateCaching: true,
},
});
},
)
// https://developer.chrome.com/blog/private-prefetch-proxy/
.match("/.well-known/traffic-advice", ({ send, setResponseHeader, cache }) => {
setResponseHeader("Content-Type", "application/trafficadvice+json");
send('[{"user_agent": "prefetch-proxy","fraction": 1.0}]', 200);
cache({
edge: {
maxAgeSeconds: 60 * 60 * 24,
staleWhileRevalidateSeconds: 60 * 60 * 24 * 7,
forcePrivateCaching: true,
},
});
})
.match("/.well-known/security.txt", ({ send, cache }) => {
send("Contact: https://github.com/cohstats\nPreferred-Languages: en, cz", 200);
cache({
edge: {
maxAgeSeconds: 60 * 60 * 24 * 14,
staleWhileRevalidateSeconds: 60 * 60 * 24 * 14,
forcePrivateCaching: true,
},
});
})
// Homepage caching
.match("/", ({ cache }) => {
cache({
edge: {
// Cache for 5 minutes, revalidate under 30 minutes
maxAgeSeconds: 60 * 5,
staleWhileRevalidateSeconds: 60 * 30,
forcePrivateCaching: true,
},
});
})
// Homepage caching data
.match("/_next/data/:version/index.json", ({ cache }) => {
cache({
browser: {
serviceWorkerSeconds: 60,
},
edge: {
maxAgeSeconds: 60 * 5,
staleWhileRevalidateSeconds: 60 * 60,
forcePrivateCaching: true,
},
});
})
.match("/api/onlineSteamPlayers", ({ cache }) => {
cache({
browser: {
serviceWorkerSeconds: 5 * 60, // Cache 5 minutes
},
edge: {
// Cache for 3 minutes, if we are older than 3 minutes, revalidate, still serve cache
maxAgeSeconds: 3 * 60,
staleWhileRevalidateSeconds: 15 * 60,
forcePrivateCaching: true,
},
});
})
// Caching for leaderboards
.match("/leaderboards(.*)", ({ cache }) => {
cache({
edge: {
maxAgeSeconds: 10,
staleWhileRevalidateSeconds: 60,
forcePrivateCaching: true,
},
});
})
.match("/_next/data/:version/leaderboards.json", ({ cache }) => {
cache({
browser: {
serviceWorkerSeconds: 15,
},
edge: {
// Cache for 30 seconds, revalidated after 5 seconds
maxAgeSeconds: 10,
staleWhileRevalidateSeconds: 60,
forcePrivateCaching: true,
},
});
})
// Caching for players
.match("/players(.*)", ({ cache, setResponseHeader }) => {
cache({
edge: {
// Cache for 30 seconds, revalidated after 5 seconds
maxAgeSeconds: 15,
staleWhileRevalidateSeconds: 45,
forcePrivateCaching: true,
},
});
// Set nofollow for players, so the bots don't go on the leaderboards
setResponseHeader("x-robots-tag", "nofollow");
})
.match("/_next/data/:version/players/:id.json", ({ cache }) => {
cache({
browser: {
serviceWorkerSeconds: 15,
},
edge: {
// Cache for 30 seconds, revalidated after 5 seconds
maxAgeSeconds: 14,
staleWhileRevalidateSeconds: 45,
forcePrivateCaching: true,
},
});
})
// Caching for desktop app
.match("/desktop-app(.*)", ({ cache }) => {
cache({
edge: {
// Add 5 minutes cache
maxAgeSeconds: 60 * 5,
// Server stale page up to 24 hours
staleWhileRevalidateSeconds: 24 * 60 * 60,
forcePrivateCaching: true,
},
});
})
.match("/_next/data/:version/desktop-app.json", ({ cache }) => {
cache({
browser: {
serviceWorkerSeconds: 60,
},
edge: {
// Cache for 15 minutes
maxAgeSeconds: 60 * 15,
// Server stale page up to 24 hours
staleWhileRevalidateSeconds: 24 * 60 * 60,
forcePrivateCaching: true,
},
});
})
// Caching for desktop app
.match("/news(.*)", ({ cache }) => {
cache({
browser: {
serviceWorkerSeconds: 60 * 30,
},
// The cache is setup in nextjs response
});
})
.match("/_next/data/:version/news.json", ({ cache }) => {
cache({
browser: {
serviceWorkerSeconds: 60 * 30,
},
// The cache is setup in nextjs response
});
})
// Caching for SSG - explorer
.match("/_next/data/:version/explorer/races/(.*)", ({ cache }) => {
cache({
browser: {
// Cache for 1 day in browser
serviceWorkerSeconds: 60 * 60 * 24,
},
// Edge cache should be automatic for SSG pages
});
})
// Caching for leaderboard stats
.match("/stats/leaderboards(.*)", ({ cache }) => {
cache({
edge: {
maxAgeSeconds: 60 * 20,
// Server stale page up to 24 hours
staleWhileRevalidateSeconds: 24 * 60 * 60,
forcePrivateCaching: true,
},
});
})
.match("/_next/data/:version/stats/leaderboards.json", ({ cache }) => {
cache({
browser: {
serviceWorkerSeconds: 60 * 20,
},
edge: {
maxAgeSeconds: 60 * 20,
// Server stale page up to 24 hours
staleWhileRevalidateSeconds: 24 * 60 * 60,
forcePrivateCaching: true,
},
});
})
// Caching for player stats
// TODO: Rewrite this to use header Cache-Control: s-maxage:, returned from the page itself
.match("/stats/players(.*)", ({ cache }) => {
cache({
edge: {
maxAgeSeconds: 1800,
// Server stale page up to 24 hours
staleWhileRevalidateSeconds: 24 * 60 * 60,
forcePrivateCaching: true,
},
});
})
.match("/_next/data/:version/stats/players.json", ({ cache }) => {
cache({
browser: {
serviceWorkerSeconds: 60 * 30,
},
edge: {
maxAgeSeconds: 1800,
// Server stale page up to 24 hours
staleWhileRevalidateSeconds: 24 * 60 * 60,
forcePrivateCaching: true,
},
});
})
// Caching for search
.match("/search(.*)", ({ cache }) => {
cache({
edge: {
// Cache for 30 seconds, revalidated after 5 seconds
maxAgeSeconds: 5 * 60,
staleWhileRevalidateSeconds: 10 * 60,
forcePrivateCaching: true,
},
});
})
.match("/_next/data/:version/search.json", ({ cache }) => {
cache({
browser: {
serviceWorkerSeconds: 60,
},
edge: {
// Cache for 30 seconds, revalidated after 5 seconds
maxAgeSeconds: 5 * 60,
staleWhileRevalidateSeconds: 10 * 60,
forcePrivateCaching: true,
},
});
});