Skip to content

Commit 266acbd

Browse files
dummy commit. changed all cache windows to 2 min
1 parent e632113 commit 266acbd

5 files changed

Lines changed: 31 additions & 95 deletions

File tree

constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const STALE_IF_ERROR_CACHE_DURATION = 120;
1+
const STALE_IF_ERROR_CACHE_DURATION = 14400;
22

33
module.exports = { STALE_IF_ERROR_CACHE_DURATION };

server/handlers/cdn-caching.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ exports.addCacheHeadersToResult = function addCacheHeadersToResult({
4242
} else {
4343
res.setHeader(
4444
"Cache-Control",
45-
`public,max-age=${maxAge},s-maxage=${sMaxAge},stale-while-revalidate=120,stale-if-error=${STALE_IF_ERROR_CACHE_DURATION}`
45+
`public,max-age=${maxAge},s-maxage=120,stale-while-revalidate=120,stale-if-error=120`
4646
);
4747
}
4848

test/integration/custom-route-handler-test.js

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ function getClientStub(hostname) {
4848
page: {
4949
id: 103,
5050
title: "Testing",
51-
content:
52-
"<html><head><title>Test</title></head><body><h1>Heading</h1></body></html>",
51+
content: "<html><head><title>Test</title></head><body><h1>Heading</h1></body></html>",
5352
metadata: { header: true, footer: false },
5453
type: "static-page",
5554
"status-code": 200,
@@ -60,8 +59,7 @@ function getClientStub(hostname) {
6059
page: {
6160
id: 104,
6261
title: "Testing",
63-
content:
64-
"<html><head><title>Test</title></head><body><h1>Heading</h1></body></html>",
62+
content: "<html><head><title>Test</title></head><body><h1>Heading</h1></body></html>",
6563
metadata: { header: false, footer: false },
6664
type: "static-page",
6765
"status-code": 200,
@@ -72,8 +70,7 @@ function getClientStub(hostname) {
7270
page: {
7371
id: 105,
7472
title: "Testing mime type",
75-
content:
76-
"<html><head><title>Test</title></head><body><h1>Heading</h1></body></html>",
73+
content: "<html><head><title>Test</title></head><body><h1>Heading</h1></body></html>",
7774
metadata: {
7875
header: false,
7976
footer: false,
@@ -104,9 +101,7 @@ function createApp(loadData, routes, opts = {}) {
104101
generateRoutes: () => routes,
105102
loadData,
106103
renderLayout: (res, { contentTemplate, store }) =>
107-
res.send(
108-
JSON.stringify({ contentTemplate, store: store.getState() })
109-
),
104+
res.send(JSON.stringify({ contentTemplate, store: store.getState() })),
110105
handleNotFound: false,
111106
publisherConfig: {},
112107
},
@@ -126,10 +121,7 @@ describe("Custom Route Handler", function () {
126121
supertest(app)
127122
.get("/moved-permanently")
128123
.expect("Location", "/permanent-location")
129-
.expect(
130-
"Cache-Control",
131-
"public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400"
132-
)
124+
.expect("Cache-Control", "public,max-age=15,s-maxage=120,stale-while-revalidate=120,stale-if-error=120")
133125
.expect("Vary", /Accept\-Encoding/)
134126
.expect("Surrogate-Key", "sp/42/101")
135127
.expect("Cache-Tag", "sp/42/101")
@@ -144,10 +136,7 @@ describe("Custom Route Handler", function () {
144136
supertest(app)
145137
.get("/moved-temporarily")
146138
.expect("Location", "/temporary-location")
147-
.expect(
148-
"Cache-Control",
149-
"public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400"
150-
)
139+
.expect("Cache-Control", "public,max-age=15,s-maxage=120,stale-while-revalidate=120,stale-if-error=120")
151140
.expect("Vary", /Accept\-Encoding/)
152141
.expect("Surrogate-Key", "sp/42/102")
153142
.expect("Cache-Tag", "sp/42/102")
@@ -163,10 +152,7 @@ describe("Custom Route Handler", function () {
163152
supertest(app)
164153
.get("/static-with-header-footer")
165154
.expect("Content-Type", /html/)
166-
.expect(
167-
"Cache-Control",
168-
"public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400"
169-
)
155+
.expect("Cache-Control", "public,max-age=15,s-maxage=120,stale-while-revalidate=120,stale-if-error=120")
170156
.expect("Vary", "Accept-Encoding")
171157
.expect("Surrogate-Key", "sp/42/103")
172158
.expect("Cache-Tag", "sp/42/103")
@@ -188,19 +174,13 @@ describe("Custom Route Handler", function () {
188174
supertest(app)
189175
.get("/static-without-header-footer")
190176
.expect("Content-Type", /html/)
191-
.expect(
192-
"Cache-Control",
193-
"public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400"
194-
)
177+
.expect("Cache-Control", "public,max-age=15,s-maxage=120,stale-while-revalidate=120,stale-if-error=120")
195178
.expect("Vary", "Accept-Encoding")
196179
.expect("Surrogate-Key", "sp/42/104")
197180
.expect("Cache-Tag", "sp/42/104")
198181
.expect(200)
199182
.then((res) => {
200-
assert.equal(
201-
"<html><head><title>Test</title></head><body><h1>Heading</h1></body></html>",
202-
res.text
203-
);
183+
assert.equal("<html><head><title>Test</title></head><body><h1>Heading</h1></body></html>", res.text);
204184
})
205185
.then(done);
206186
});
@@ -233,9 +213,7 @@ describe("Custom Route Handler", function () {
233213
it("Store reads config and data from data-loader response", function (done) {
234214
const app = createApp(
235215
(pageType, params, config, client, { host, next }) =>
236-
pageType === "custom-static-page"
237-
? Promise.resolve({ data: { navigationMenu: [] }, config: {} })
238-
: next(),
216+
pageType === "custom-static-page" ? Promise.resolve({ data: { navigationMenu: [] }, config: {} }) : next(),
239217
[{ pageType: "story-page", path: "/*" }]
240218
);
241219
supertest(app)
@@ -258,10 +236,7 @@ describe("Custom Route Handler", function () {
258236
supertest(app)
259237
.get("/moved-absolute")
260238
.expect("Location", "https://www.google.com")
261-
.expect(
262-
"Cache-Control",
263-
"public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400"
264-
)
239+
.expect("Cache-Control", "public,max-age=15,s-maxage=120,stale-while-revalidate=120,stale-if-error=120")
265240
.expect("Vary", /Accept\-Encoding/)
266241
.expect("Surrogate-Key", "sp/42/105")
267242
.expect("Cache-Tag", "sp/42/105")
@@ -275,10 +250,7 @@ describe("Custom Route Handler", function () {
275250
);
276251
supertest(app)
277252
.get("/static-with-mime-type")
278-
.expect(
279-
"Cache-Control",
280-
"public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400"
281-
)
253+
.expect("Cache-Control", "public,max-age=15,s-maxage=120,stale-while-revalidate=120,stale-if-error=120")
282254
.expect("Vary", /Accept\-Encoding/)
283255
.expect("Surrogate-Key", "sp/42/105")
284256
.expect("Cache-Tag", "sp/42/105")
@@ -293,10 +265,7 @@ describe("Custom Route Handler", function () {
293265
);
294266
supertest(app)
295267
.get("/static-without-header-footer")
296-
.expect(
297-
"Cache-Control",
298-
"public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400"
299-
)
268+
.expect("Cache-Control", "public,max-age=15,s-maxage=120,stale-while-revalidate=120,stale-if-error=120")
300269
.expect("Vary", "Accept-Encoding")
301270
.expect("Surrogate-Key", "sp/42/104")
302271
.expect("Cache-Tag", "sp/42/104")

test/integration/isomorphic-handler-test.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ describe("Isomorphic Handler", function () {
200200
supertest(app)
201201
.get("/")
202202
.expect("Content-Type", /html/)
203-
.expect("Cache-Control", "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400")
203+
.expect("Cache-Control", "public,max-age=15,s-maxage=120,stale-while-revalidate=120,stale-if-error=120")
204204
.expect("Vary", "Accept-Encoding")
205205
.expect("Surrogate-Key", "foo bar")
206206
.expect("Cache-Tag", "foo,bar")
@@ -503,7 +503,7 @@ describe("Isomorphic Handler", function () {
503503
.then((res) => {
504504
const cacheControl = res.header["cache-control"];
505505
const cacheTag = res.header["cache-tag"];
506-
assert.equal(cacheControl, "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400");
506+
assert.equal(cacheControl, "public,max-age=15,s-maxage=120,stale-while-revalidate=120,stale-if-error=120");
507507
assert.equal(cacheTag, "c/1/abcdefgh");
508508
})
509509
.then(done);
@@ -631,7 +631,7 @@ describe("Isomorphic Handler", function () {
631631
const cacheControl = res.header["cache-control"];
632632
const edgeCacheTag = res.header["edge-cache-tag"];
633633
const contentSecurityPolicy = res.header["content-security-policy"];
634-
assert.equal(cacheControl, "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400");
634+
assert.equal(cacheControl, "public,max-age=15,s-maxage=120,stale-while-revalidate=120,stale-if-error=120");
635635
assert.equal(edgeCacheTag, "c/1/abcdefgh");
636636
assert.equal(
637637
contentSecurityPolicy,
@@ -670,7 +670,7 @@ describe("Isomorphic Handler", function () {
670670
const cacheControl = res.header["cache-control"];
671671
const edgeCacheTag = res.header["edge-cache-tag"];
672672
const contentSecurityPolicy = res.header["content-security-policy"];
673-
assert.equal(cacheControl, "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400");
673+
assert.equal(cacheControl, "public,max-age=15,s-maxage=120,stale-while-revalidate=120,stale-if-error=120");
674674
assert.equal(edgeCacheTag, "c/1/abcdefgh");
675675
assert.equal(
676676
contentSecurityPolicy,
@@ -706,10 +706,7 @@ describe("Isomorphic Handler", function () {
706706
.expect(200)
707707
.then((res) => {
708708
const cacheControl = res.header["cache-control"];
709-
assert.equal(
710-
cacheControl,
711-
"public,max-age=15,s-maxage=1800,stale-while-revalidate=1000,stale-if-error=14400"
712-
);
709+
assert.equal(cacheControl, "public,max-age=15,s-maxage=120,stale-while-revalidate=120,stale-if-error=120");
713710
})
714711
.then(done);
715712
});
@@ -730,7 +727,7 @@ describe("Isomorphic Handler", function () {
730727
.expect(200)
731728
.then((res) => {
732729
const cacheControl = res.header["cache-control"];
733-
assert.equal(cacheControl, "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400");
730+
assert.equal(cacheControl, "public,max-age=15,s-maxage=120,stale-while-revalidate=120,stale-if-error=120");
734731
})
735732
.then(done);
736733
});

test/integration/url-redirect-test.js

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -508,10 +508,7 @@ describe("Redirect Routes Handler", function () {
508508
redirectUrls,
509509
}
510510
);
511-
supertest(app)
512-
.get("/moved-permanently-1")
513-
.expect("Location", "/permanent-location-1")
514-
.expect(301, done);
511+
supertest(app).get("/moved-permanently-1").expect("Location", "/permanent-location-1").expect(301, done);
515512
});
516513

517514
it("Redirects all the urls with status code to 302 if redirectUrls is present", function (done) {
@@ -528,10 +525,7 @@ describe("Redirect Routes Handler", function () {
528525
],
529526
}
530527
);
531-
supertest(app)
532-
.get("/moved-temporarily-1")
533-
.expect("Location", "/temporarily-location-1")
534-
.expect(302, done);
528+
supertest(app).get("/moved-temporarily-1").expect("Location", "/temporarily-location-1").expect(302, done);
535529
});
536530

537531
it("Renders homepage when redirect urls are present", function (done) {
@@ -555,10 +549,7 @@ describe("Redirect Routes Handler", function () {
555549
.expect(200)
556550
.then((res) => {
557551
const response = JSON.parse(res.text);
558-
assert.equal(
559-
'<div data-page-type="home-page">foobar</div>',
560-
response.content
561-
);
552+
assert.equal('<div data-page-type="home-page">foobar</div>', response.content);
562553
assert.equal("foobar", response.store.qt.data.text);
563554
assert.equal("127.0.0.1", response.store.qt.data.host);
564555
assert.equal("home-page", response.store.qt.pageType);
@@ -572,10 +563,7 @@ describe("Redirect Routes Handler", function () {
572563
[{ pageType: "story-page", path: "/*" }],
573564
{ redirectUrls: getRedirectUrl }
574565
);
575-
supertest(app)
576-
.get("/moved-permanently-1")
577-
.expect("Location", "/permanent-location-1")
578-
.expect(301, done);
566+
supertest(app).get("/moved-permanently-1").expect("Location", "/permanent-location-1").expect(301, done);
579567
});
580568

581569
it("Should handle Route Parameters redirects properly", function (done) {
@@ -584,10 +572,7 @@ describe("Redirect Routes Handler", function () {
584572
[{ pageType: "story-page", path: "/*" }],
585573
{ redirectUrls: getRedirectUrl }
586574
);
587-
supertest(app)
588-
.get("/india/news/some-slug")
589-
.expect("Location", "/india/some-slug")
590-
.expect(301, done);
575+
supertest(app).get("/india/news/some-slug").expect("Location", "/india/some-slug").expect(301, done);
591576
});
592577

593578
it("Should handle multiple Route Parameters redirects properly", function (done) {
@@ -596,10 +581,7 @@ describe("Redirect Routes Handler", function () {
596581
[{ pageType: "story-page", path: "/*" }],
597582
{ redirectUrls: getRedirectUrl }
598583
);
599-
supertest(app)
600-
.get("/india/foo/some-slug/slug")
601-
.expect("Location", "/india/some-slug")
602-
.expect(302, done);
584+
supertest(app).get("/india/foo/some-slug/slug").expect("Location", "/india/some-slug").expect(302, done);
603585
});
604586

605587
it("Should handle interchanging route parameter redirects properly", function (done) {
@@ -608,10 +590,7 @@ describe("Redirect Routes Handler", function () {
608590
[{ pageType: "story-page", path: "/*" }],
609591
{ redirectUrls: getRedirectUrl }
610592
);
611-
supertest(app)
612-
.get("/foo/something/bar")
613-
.expect("Location", "/bar/something/foo")
614-
.expect(301, done);
593+
supertest(app).get("/foo/something/bar").expect("Location", "/bar/something/foo").expect(301, done);
615594
});
616595

617596
it("Should handle external redirects", function (done) {
@@ -620,10 +599,7 @@ describe("Redirect Routes Handler", function () {
620599
[{ pageType: "story-page", path: "/*" }],
621600
{ redirectUrls: getRedirectUrl }
622601
);
623-
supertest(app)
624-
.get("/something/new")
625-
.expect("Location", "https://www.google.com/something")
626-
.expect(301, done);
602+
supertest(app).get("/something/new").expect("Location", "https://www.google.com/something").expect(301, done);
627603
});
628604

629605
it("Should handle external redirects with params", function (done) {
@@ -632,10 +608,7 @@ describe("Redirect Routes Handler", function () {
632608
[{ pageType: "story-page", path: "/*" }],
633609
{ redirectUrls: getRedirectUrl }
634610
);
635-
supertest(app)
636-
.get("/something/new1")
637-
.expect("Location", "https://www.google.com/new1")
638-
.expect(301, done);
611+
supertest(app).get("/something/new1").expect("Location", "https://www.google.com/new1").expect(301, done);
639612
});
640613

641614
it("Should not crash if redirectUrls is not present", function (done) {
@@ -646,10 +619,7 @@ describe("Redirect Routes Handler", function () {
646619
supertest(app)
647620
.get("/moved-temporarily-1")
648621
.expect("Location", "/temporarily-location-1")
649-
.expect(
650-
"Cache-Control",
651-
"public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400"
652-
)
622+
.expect("Cache-Control", "public,max-age=15,s-maxage=120,stale-while-revalidate=120,stale-if-error=120")
653623
.expect("Vary", /Accept\-Encoding/)
654624
.expect("Surrogate-Key", "sp/42/102")
655625
.expect("Cache-Tag", "sp/42/102")

0 commit comments

Comments
 (0)