@quintype/framework 7.34.7-handle-500-issue.0 → 7.34.7-handle-500-issue.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintype/framework",
3
- "version": "7.34.7-handle-500-issue.0",
3
+ "version": "7.34.7-handle-500-issue.2",
4
4
  "description": "Libraries to help build Quintype Node.js apps",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -42,7 +42,7 @@ exports.addCacheHeadersToResult = function addCacheHeadersToResult({
42
42
  } else {
43
43
  res.setHeader(
44
44
  "Cache-Control",
45
- `public,max-age=${maxAge},s-maxage=${sMaxAge},stale-while-revalidate=1000,stale-if-error=${STALE_IF_ERROR_CACHE_DURATION}`
45
+ `public,max-age=${maxAge},s-maxage=120,stale-while-revalidate=120,stale-if-error=120`
46
46
  );
47
47
  }
48
48
 
@@ -486,9 +486,9 @@ exports.handleIsomorphicRoute = function handleIsomorphicRoute(
486
486
  return res.redirect(301, result.data.location);
487
487
  }
488
488
 
489
- if (statusCode == 500) {
490
- console.log("RESULT 111 =============>>>", statusCode);
491
- return res.sendStatus(500);
489
+ // For server errors (>=500),send statuss
490
+ if (statusCode >= 500) {
491
+ return res.sendStatus(statusCode);
492
492
  }
493
493
 
494
494
  const seoInstance = getSeoInstance(seo, config, result.pageType);
@@ -48,8 +48,7 @@ function getClientStub(hostname) {
48
48
  page: {
49
49
  id: 103,
50
50
  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>",
53
52
  metadata: { header: true, footer: false },
54
53
  type: "static-page",
55
54
  "status-code": 200,
@@ -60,8 +59,7 @@ function getClientStub(hostname) {
60
59
  page: {
61
60
  id: 104,
62
61
  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>",
65
63
  metadata: { header: false, footer: false },
66
64
  type: "static-page",
67
65
  "status-code": 200,
@@ -72,8 +70,7 @@ function getClientStub(hostname) {
72
70
  page: {
73
71
  id: 105,
74
72
  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>",
77
74
  metadata: {
78
75
  header: false,
79
76
  footer: false,
@@ -104,9 +101,7 @@ function createApp(loadData, routes, opts = {}) {
104
101
  generateRoutes: () => routes,
105
102
  loadData,
106
103
  renderLayout: (res, { contentTemplate, store }) =>
107
- res.send(
108
- JSON.stringify({ contentTemplate, store: store.getState() })
109
- ),
104
+ res.send(JSON.stringify({ contentTemplate, store: store.getState() })),
110
105
  handleNotFound: false,
111
106
  publisherConfig: {},
112
107
  },
@@ -126,10 +121,7 @@ describe("Custom Route Handler", function () {
126
121
  supertest(app)
127
122
  .get("/moved-permanently")
128
123
  .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")
133
125
  .expect("Vary", /Accept\-Encoding/)
134
126
  .expect("Surrogate-Key", "sp/42/101")
135
127
  .expect("Cache-Tag", "sp/42/101")
@@ -144,10 +136,7 @@ describe("Custom Route Handler", function () {
144
136
  supertest(app)
145
137
  .get("/moved-temporarily")
146
138
  .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")
151
140
  .expect("Vary", /Accept\-Encoding/)
152
141
  .expect("Surrogate-Key", "sp/42/102")
153
142
  .expect("Cache-Tag", "sp/42/102")
@@ -163,10 +152,7 @@ describe("Custom Route Handler", function () {
163
152
  supertest(app)
164
153
  .get("/static-with-header-footer")
165
154
  .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")
170
156
  .expect("Vary", "Accept-Encoding")
171
157
  .expect("Surrogate-Key", "sp/42/103")
172
158
  .expect("Cache-Tag", "sp/42/103")
@@ -188,19 +174,13 @@ describe("Custom Route Handler", function () {
188
174
  supertest(app)
189
175
  .get("/static-without-header-footer")
190
176
  .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")
195
178
  .expect("Vary", "Accept-Encoding")
196
179
  .expect("Surrogate-Key", "sp/42/104")
197
180
  .expect("Cache-Tag", "sp/42/104")
198
181
  .expect(200)
199
182
  .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);
204
184
  })
205
185
  .then(done);
206
186
  });
@@ -233,9 +213,7 @@ describe("Custom Route Handler", function () {
233
213
  it("Store reads config and data from data-loader response", function (done) {
234
214
  const app = createApp(
235
215
  (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(),
239
217
  [{ pageType: "story-page", path: "/*" }]
240
218
  );
241
219
  supertest(app)
@@ -258,10 +236,7 @@ describe("Custom Route Handler", function () {
258
236
  supertest(app)
259
237
  .get("/moved-absolute")
260
238
  .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")
265
240
  .expect("Vary", /Accept\-Encoding/)
266
241
  .expect("Surrogate-Key", "sp/42/105")
267
242
  .expect("Cache-Tag", "sp/42/105")
@@ -275,10 +250,7 @@ describe("Custom Route Handler", function () {
275
250
  );
276
251
  supertest(app)
277
252
  .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")
282
254
  .expect("Vary", /Accept\-Encoding/)
283
255
  .expect("Surrogate-Key", "sp/42/105")
284
256
  .expect("Cache-Tag", "sp/42/105")
@@ -293,10 +265,7 @@ describe("Custom Route Handler", function () {
293
265
  );
294
266
  supertest(app)
295
267
  .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")
300
269
  .expect("Vary", "Accept-Encoding")
301
270
  .expect("Surrogate-Key", "sp/42/104")
302
271
  .expect("Cache-Tag", "sp/42/104")
@@ -154,31 +154,22 @@ describe("Isomorphic Handler", function () {
154
154
  .then(done);
155
155
  });
156
156
 
157
- // it("Throws a 500 if loadData doesn't work", function (done) {
158
- // const app = createApp(
159
- // (pageType, params, config, client) => {
160
- // throw "exception";
161
- // },
162
- // [{ pageType: "home-page", path: "/" }],
163
- // {
164
- // loadErrorData: (err, config) => ({
165
- // httpStatusCode: err.httpStatusCode || 500,
166
- // pageType: "not-found",
167
- // data: { text: "foobar" },
168
- // }),
169
- // }
170
- // );
171
- // supertest(app)
172
- // .get("/")
173
- // .expect("Content-Type", /html/)
174
- // .expect(500)
175
- // .then((res) => {
176
- // const response = JSON.parse(res.text);
177
- // assert.equal('<div data-page-type="not-found">foobar</div>', response.content);
178
- // assert.equal(true, response.store.qt.disableIsomorphicComponent);
179
- // })
180
- // .then(done, done);
181
- // });
157
+ it("Throws a 500 if loadData doesn't work", function (done) {
158
+ const app = createApp(
159
+ (pageType, params, config, client) => {
160
+ throw "exception";
161
+ },
162
+ [{ pageType: "home-page", path: "/" }],
163
+ {
164
+ loadErrorData: (err, config) => ({
165
+ httpStatusCode: err.httpStatusCode || 500,
166
+ pageType: "not-found",
167
+ data: { text: "foobar" },
168
+ }),
169
+ }
170
+ );
171
+ supertest(app).get("/").expect(500, done);
172
+ });
182
173
 
183
174
  it("Throws a 500 if loadData and loadErrorData both crash", function (done) {
184
175
  const app = createApp(
@@ -193,7 +184,7 @@ describe("Isomorphic Handler", function () {
193
184
  }
194
185
  );
195
186
 
196
- supertest(app).get("/").expect("Content-Type", /html/).expect(500, done);
187
+ supertest(app).get("/").expect(500, done);
197
188
  });
198
189
 
199
190
  it("Cache headers are set", function (done) {
@@ -209,7 +200,7 @@ describe("Isomorphic Handler", function () {
209
200
  supertest(app)
210
201
  .get("/")
211
202
  .expect("Content-Type", /html/)
212
- .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")
213
204
  .expect("Vary", "Accept-Encoding")
214
205
  .expect("Surrogate-Key", "foo bar")
215
206
  .expect("Cache-Tag", "foo,bar")
@@ -512,7 +503,7 @@ describe("Isomorphic Handler", function () {
512
503
  .then((res) => {
513
504
  const cacheControl = res.header["cache-control"];
514
505
  const cacheTag = res.header["cache-tag"];
515
- 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");
516
507
  assert.equal(cacheTag, "c/1/abcdefgh");
517
508
  })
518
509
  .then(done);
@@ -640,7 +631,7 @@ describe("Isomorphic Handler", function () {
640
631
  const cacheControl = res.header["cache-control"];
641
632
  const edgeCacheTag = res.header["edge-cache-tag"];
642
633
  const contentSecurityPolicy = res.header["content-security-policy"];
643
- 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");
644
635
  assert.equal(edgeCacheTag, "c/1/abcdefgh");
645
636
  assert.equal(
646
637
  contentSecurityPolicy,
@@ -679,7 +670,7 @@ describe("Isomorphic Handler", function () {
679
670
  const cacheControl = res.header["cache-control"];
680
671
  const edgeCacheTag = res.header["edge-cache-tag"];
681
672
  const contentSecurityPolicy = res.header["content-security-policy"];
682
- 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");
683
674
  assert.equal(edgeCacheTag, "c/1/abcdefgh");
684
675
  assert.equal(
685
676
  contentSecurityPolicy,
@@ -715,10 +706,7 @@ describe("Isomorphic Handler", function () {
715
706
  .expect(200)
716
707
  .then((res) => {
717
708
  const cacheControl = res.header["cache-control"];
718
- assert.equal(
719
- cacheControl,
720
- "public,max-age=15,s-maxage=1800,stale-while-revalidate=1000,stale-if-error=14400"
721
- );
709
+ assert.equal(cacheControl, "public,max-age=15,s-maxage=120,stale-while-revalidate=120,stale-if-error=120");
722
710
  })
723
711
  .then(done);
724
712
  });
@@ -739,7 +727,7 @@ describe("Isomorphic Handler", function () {
739
727
  .expect(200)
740
728
  .then((res) => {
741
729
  const cacheControl = res.header["cache-control"];
742
- 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");
743
731
  })
744
732
  .then(done);
745
733
  });
@@ -508,10 +508,7 @@ describe("Redirect Routes Handler", function () {
508
508
  redirectUrls,
509
509
  }
510
510
  );
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);
515
512
  });
516
513
 
517
514
  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 () {
528
525
  ],
529
526
  }
530
527
  );
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);
535
529
  });
536
530
 
537
531
  it("Renders homepage when redirect urls are present", function (done) {
@@ -555,10 +549,7 @@ describe("Redirect Routes Handler", function () {
555
549
  .expect(200)
556
550
  .then((res) => {
557
551
  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);
562
553
  assert.equal("foobar", response.store.qt.data.text);
563
554
  assert.equal("127.0.0.1", response.store.qt.data.host);
564
555
  assert.equal("home-page", response.store.qt.pageType);
@@ -572,10 +563,7 @@ describe("Redirect Routes Handler", function () {
572
563
  [{ pageType: "story-page", path: "/*" }],
573
564
  { redirectUrls: getRedirectUrl }
574
565
  );
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);
579
567
  });
580
568
 
581
569
  it("Should handle Route Parameters redirects properly", function (done) {
@@ -584,10 +572,7 @@ describe("Redirect Routes Handler", function () {
584
572
  [{ pageType: "story-page", path: "/*" }],
585
573
  { redirectUrls: getRedirectUrl }
586
574
  );
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);
591
576
  });
592
577
 
593
578
  it("Should handle multiple Route Parameters redirects properly", function (done) {
@@ -596,10 +581,7 @@ describe("Redirect Routes Handler", function () {
596
581
  [{ pageType: "story-page", path: "/*" }],
597
582
  { redirectUrls: getRedirectUrl }
598
583
  );
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);
603
585
  });
604
586
 
605
587
  it("Should handle interchanging route parameter redirects properly", function (done) {
@@ -608,10 +590,7 @@ describe("Redirect Routes Handler", function () {
608
590
  [{ pageType: "story-page", path: "/*" }],
609
591
  { redirectUrls: getRedirectUrl }
610
592
  );
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);
615
594
  });
616
595
 
617
596
  it("Should handle external redirects", function (done) {
@@ -620,10 +599,7 @@ describe("Redirect Routes Handler", function () {
620
599
  [{ pageType: "story-page", path: "/*" }],
621
600
  { redirectUrls: getRedirectUrl }
622
601
  );
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);
627
603
  });
628
604
 
629
605
  it("Should handle external redirects with params", function (done) {
@@ -632,10 +608,7 @@ describe("Redirect Routes Handler", function () {
632
608
  [{ pageType: "story-page", path: "/*" }],
633
609
  { redirectUrls: getRedirectUrl }
634
610
  );
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);
639
612
  });
640
613
 
641
614
  it("Should not crash if redirectUrls is not present", function (done) {
@@ -646,10 +619,7 @@ describe("Redirect Routes Handler", function () {
646
619
  supertest(app)
647
620
  .get("/moved-temporarily-1")
648
621
  .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")
653
623
  .expect("Vary", /Accept\-Encoding/)
654
624
  .expect("Surrogate-Key", "sp/42/102")
655
625
  .expect("Cache-Tag", "sp/42/102")