Skip to content

Commit 3bb6eba

Browse files
RealOrangeOnehelenb
authored andcommitted
Lint worker
1 parent 20feb93 commit 3bb6eba

File tree

2 files changed

+79
-70
lines changed

2 files changed

+79
-70
lines changed

cloudflare/workers.js

Lines changed: 78 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,72 +3,72 @@
33
// applied after this worker runs.
44

55
// When any cookie in this list is present in the request, cache will be skipped
6-
const PRIVATE_COOKIES = ["sessionid"];
6+
const PRIVATE_COOKIES = ['sessionid'];
77

88
// These querystring keys are stripped from the request as they are generally not
99
// needed by the origin.
1010
const STRIP_QUERYSTRING_KEYS = [
11-
"utm_source",
12-
"utm_campaign",
13-
"utm_medium",
14-
"utm_term",
15-
"utm_content",
16-
"gclid",
17-
"fbclid",
18-
"dm_i", // DotDigital
19-
"msclkid",
20-
"al_applink_data", // Meta outbound app links
11+
'utm_source',
12+
'utm_campaign',
13+
'utm_medium',
14+
'utm_term',
15+
'utm_content',
16+
'gclid',
17+
'fbclid',
18+
'dm_i', // DotDigital
19+
'msclkid',
20+
'al_applink_data', // Meta outbound app links
2121

2222
// https://docs.flying-press.com/cache/ignore-query-strings
23-
"age-verified",
24-
"ao_noptimize",
25-
"usqp",
26-
"cn-reloaded",
27-
"sscid",
28-
"ef_id",
29-
"_bta_tid",
30-
"_bta_c",
31-
"fb_action_ids",
32-
"fb_action_types",
33-
"fb_source",
34-
"_ga",
35-
"adid",
36-
"_gl",
37-
"gclsrc",
38-
"gdfms",
39-
"gdftrk",
40-
"gdffi",
41-
"_ke",
42-
"trk_contact",
43-
"trk_msg",
44-
"trk_module",
45-
"trk_sid",
46-
"mc_cid",
47-
"mc_eid",
48-
"mkwid",
49-
"pcrid",
50-
"mtm_source",
51-
"mtm_medium",
52-
"mtm_campaign",
53-
"mtm_keyword",
54-
"mtm_cid",
55-
"mtm_content",
56-
"epik",
57-
"pp",
58-
"pk_source",
59-
"pk_medium",
60-
"pk_campaign",
61-
"pk_keyword",
62-
"pk_cid",
63-
"pk_content",
64-
"redirect_log_mongo_id",
65-
"redirect_mongo_id",
66-
"sb_referer_host",
23+
'age-verified',
24+
'ao_noptimize',
25+
'usqp',
26+
'cn-reloaded',
27+
'sscid',
28+
'ef_id',
29+
'_bta_tid',
30+
'_bta_c',
31+
'fb_action_ids',
32+
'fb_action_types',
33+
'fb_source',
34+
'_ga',
35+
'adid',
36+
'_gl',
37+
'gclsrc',
38+
'gdfms',
39+
'gdftrk',
40+
'gdffi',
41+
'_ke',
42+
'trk_contact',
43+
'trk_msg',
44+
'trk_module',
45+
'trk_sid',
46+
'mc_cid',
47+
'mc_eid',
48+
'mkwid',
49+
'pcrid',
50+
'mtm_source',
51+
'mtm_medium',
52+
'mtm_campaign',
53+
'mtm_keyword',
54+
'mtm_cid',
55+
'mtm_content',
56+
'epik',
57+
'pp',
58+
'pk_source',
59+
'pk_medium',
60+
'pk_campaign',
61+
'pk_keyword',
62+
'pk_cid',
63+
'pk_content',
64+
'redirect_log_mongo_id',
65+
'redirect_mongo_id',
66+
'sb_referer_host',
6767
];
6868

6969
// If this is true, the querystring keys stripped from the request will be
7070
// addeed to any Location header served by a redirect.
71-
const REPLACE_STRIPPED_QUERYSTRING_ON_REDIRECT_LOCATION = false
71+
const REPLACE_STRIPPED_QUERYSTRING_ON_REDIRECT_LOCATION = false;
7272

7373
// If this is true, querystring key are stripped if they have no value eg. ?foo
7474
// Disabled by default, but highly recommended
@@ -78,7 +78,7 @@ const STRIP_VALUELESS_QUERYSTRING_KEYS = false;
7878
// (from https://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.4)
7979
const CACHABLE_HTTP_STATUS_CODES = [200, 203, 206, 300, 301, 410];
8080

81-
addEventListener("fetch", (event) => {
81+
addEventListener('fetch', (event) => {
8282
event.respondWith(main(event));
8383
});
8484

@@ -106,7 +106,10 @@ async function main(event) {
106106
}
107107

108108
if (REPLACE_STRIPPED_QUERYSTRING_ON_REDIRECT_LOCATION) {
109-
response = replaceStrippedQsOnRedirectResponse(response, strippedParams);
109+
response = replaceStrippedQsOnRedirectResponse(
110+
response,
111+
strippedParams,
112+
);
110113
}
111114

112115
return response;
@@ -120,15 +123,15 @@ function requestIsCachable(request) {
120123
* Given a Request, determine if it should be cached.
121124
* Currently the only factor here is whether a private cookie is present.
122125
*/
123-
return !hasPrivateCookie(request)
126+
return !hasPrivateCookie(request);
124127
}
125128

126129
function responseIsCachable(response) {
127130
/*
128131
* Given a Response, determine if it should be cached.
129132
* Currently the only factor here is whether the status code is cachable.
130133
*/
131-
return CACHABLE_HTTP_STATUS_CODES.includes(response.status)
134+
return CACHABLE_HTTP_STATUS_CODES.includes(response.status);
132135
}
133136

134137
function getCachingRequest(request) {
@@ -142,12 +145,14 @@ function getCachingRequest(request) {
142145
const requestURL = new URL(request.url);
143146

144147
// Cache based on the mode
145-
requestURL.searchParams.set('cookie-torchbox-mode', cookies['torchbox-mode'] || 'dark');
148+
requestURL.searchParams.set(
149+
'cookie-torchbox-mode',
150+
cookies['torchbox-mode'] || 'dark',
151+
);
146152

147153
return new Request(requestURL, request);
148154
}
149155

150-
151156
/*
152157
* Request Utilities
153158
*/
@@ -189,7 +194,7 @@ function hasPrivateCookie(request) {
189194
/*
190195
* Given a Request, determine if one of the 'private' cookies are present.
191196
*/
192-
const cookieHeader = request.headers.get("Cookie");
197+
const cookieHeader = request.headers.get('Cookie');
193198
if (!cookieHeader) {
194199
return false;
195200
}
@@ -234,7 +239,7 @@ function replaceStrippedQsOnRedirectResponse(response, strippedParams) {
234239
response = new Response(response.body, response);
235240

236241
if ([301, 302].includes(response.status)) {
237-
const locationHeaderValue = response.headers.get("location");
242+
const locationHeaderValue = response.headers.get('location');
238243
let locationUrl;
239244

240245
if (!locationHeaderValue) {
@@ -246,9 +251,12 @@ function replaceStrippedQsOnRedirectResponse(response, strippedParams) {
246251
if (!isAbsolute) {
247252
// If the Location URL isn't absolute, we need to provide a Host so we can use
248253
// a URL object.
249-
locationUrl = new URL(locationHeaderValue, "http://www.example.com");
254+
locationUrl = new URL(
255+
locationHeaderValue,
256+
'http://www.example.com',
257+
);
250258
} else {
251-
locationUrl = new URL(locationHeaderValue)
259+
locationUrl = new URL(locationHeaderValue);
252260
}
253261

254262
for (const [key, value] of Object.entries(strippedParams)) {
@@ -258,20 +266,20 @@ function replaceStrippedQsOnRedirectResponse(response, strippedParams) {
258266
let newLocation;
259267

260268
if (isAbsolute) {
261-
newLocation = locationUrl.toString()
269+
newLocation = locationUrl.toString();
262270
} else {
263271
newLocation = `${locationUrl.pathname}${locationUrl.search}`;
264272
}
265273

266-
response.headers.set("location", newLocation);
274+
response.headers.set('location', newLocation);
267275
}
268276

269-
return response
277+
return response;
270278
}
271279

272280
/**
273281
* URL Utilities
274282
*/
275283
function isUrlAbsolute(url) {
276-
return (url.indexOf('://') > 0 || url.indexOf('//') === 0);
284+
return url.indexOf('://') > 0 || url.indexOf('//') === 0;
277285
}

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ services:
4040
- ./manage.py:/app/manage.py:rw
4141
- ./pyproject.toml:/app/pyproject.toml:rw
4242
- ./poetry.lock:/app/poetry.lock:rw
43+
- ./cloudflare:/app/cloudflare:rw
4344

4445
# Frontend config
4546
- ./.babelrc.js:/app/.babelrc.js:rw

0 commit comments

Comments
 (0)