Skip to content
Open
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@quintype/framework",
"version": "7.34.6",
"version": "7.34.7-handle-500-issue.3",
"description": "Libraries to help build Quintype Node.js apps",
"main": "index.js",
"engines": {
Expand Down
7 changes: 6 additions & 1 deletion server/handlers/isomorphic-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function loadDataForPageType(
.then((result) => {
if (result && result.data) {
if (result.data[ABORT_HANDLER] || (result.data.error && result.data.error.message)) {
return null
return null;
}
}
return result;
Expand Down Expand Up @@ -485,6 +485,11 @@ exports.handleIsomorphicRoute = function handleIsomorphicRoute(
});
return res.redirect(301, result.data.location);
}

if (statusCode >= 500) {
return res.sendStatus(statusCode);
}

const seoInstance = getSeoInstance(seo, config, result.pageType);
const seoTags = seoInstance && seoInstance.getMetaTags(config, result.pageType || match.pageType, result, { url });

Expand Down
57 changes: 13 additions & 44 deletions test/integration/custom-route-handler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ function getClientStub(hostname) {
page: {
id: 103,
title: "Testing",
content:
"<html><head><title>Test</title></head><body><h1>Heading</h1></body></html>",
content: "<html><head><title>Test</title></head><body><h1>Heading</h1></body></html>",
metadata: { header: true, footer: false },
type: "static-page",
"status-code": 200,
Expand All @@ -60,8 +59,7 @@ function getClientStub(hostname) {
page: {
id: 104,
title: "Testing",
content:
"<html><head><title>Test</title></head><body><h1>Heading</h1></body></html>",
content: "<html><head><title>Test</title></head><body><h1>Heading</h1></body></html>",
metadata: { header: false, footer: false },
type: "static-page",
"status-code": 200,
Expand All @@ -72,8 +70,7 @@ function getClientStub(hostname) {
page: {
id: 105,
title: "Testing mime type",
content:
"<html><head><title>Test</title></head><body><h1>Heading</h1></body></html>",
content: "<html><head><title>Test</title></head><body><h1>Heading</h1></body></html>",
metadata: {
header: false,
footer: false,
Expand Down Expand Up @@ -104,9 +101,7 @@ function createApp(loadData, routes, opts = {}) {
generateRoutes: () => routes,
loadData,
renderLayout: (res, { contentTemplate, store }) =>
res.send(
JSON.stringify({ contentTemplate, store: store.getState() })
),
res.send(JSON.stringify({ contentTemplate, store: store.getState() })),
handleNotFound: false,
publisherConfig: {},
},
Expand All @@ -126,10 +121,7 @@ describe("Custom Route Handler", function () {
supertest(app)
.get("/moved-permanently")
.expect("Location", "/permanent-location")
.expect(
"Cache-Control",
"public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400"
)
.expect("Cache-Control", "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400")
.expect("Vary", /Accept\-Encoding/)
.expect("Surrogate-Key", "sp/42/101")
.expect("Cache-Tag", "sp/42/101")
Expand All @@ -144,10 +136,7 @@ describe("Custom Route Handler", function () {
supertest(app)
.get("/moved-temporarily")
.expect("Location", "/temporary-location")
.expect(
"Cache-Control",
"public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400"
)
.expect("Cache-Control", "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400")
.expect("Vary", /Accept\-Encoding/)
.expect("Surrogate-Key", "sp/42/102")
.expect("Cache-Tag", "sp/42/102")
Expand All @@ -163,10 +152,7 @@ describe("Custom Route Handler", function () {
supertest(app)
.get("/static-with-header-footer")
.expect("Content-Type", /html/)
.expect(
"Cache-Control",
"public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400"
)
.expect("Cache-Control", "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400")
.expect("Vary", "Accept-Encoding")
.expect("Surrogate-Key", "sp/42/103")
.expect("Cache-Tag", "sp/42/103")
Expand All @@ -188,19 +174,13 @@ describe("Custom Route Handler", function () {
supertest(app)
.get("/static-without-header-footer")
.expect("Content-Type", /html/)
.expect(
"Cache-Control",
"public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400"
)
.expect("Cache-Control", "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400")
.expect("Vary", "Accept-Encoding")
.expect("Surrogate-Key", "sp/42/104")
.expect("Cache-Tag", "sp/42/104")
.expect(200)
.then((res) => {
assert.equal(
"<html><head><title>Test</title></head><body><h1>Heading</h1></body></html>",
res.text
);
assert.equal("<html><head><title>Test</title></head><body><h1>Heading</h1></body></html>", res.text);
})
.then(done);
});
Expand Down Expand Up @@ -233,9 +213,7 @@ describe("Custom Route Handler", function () {
it("Store reads config and data from data-loader response", function (done) {
const app = createApp(
(pageType, params, config, client, { host, next }) =>
pageType === "custom-static-page"
? Promise.resolve({ data: { navigationMenu: [] }, config: {} })
: next(),
pageType === "custom-static-page" ? Promise.resolve({ data: { navigationMenu: [] }, config: {} }) : next(),
[{ pageType: "story-page", path: "/*" }]
);
supertest(app)
Expand All @@ -258,10 +236,7 @@ describe("Custom Route Handler", function () {
supertest(app)
.get("/moved-absolute")
.expect("Location", "https://www.google.com")
.expect(
"Cache-Control",
"public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400"
)
.expect("Cache-Control", "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400")
.expect("Vary", /Accept\-Encoding/)
.expect("Surrogate-Key", "sp/42/105")
.expect("Cache-Tag", "sp/42/105")
Expand All @@ -275,10 +250,7 @@ describe("Custom Route Handler", function () {
);
supertest(app)
.get("/static-with-mime-type")
.expect(
"Cache-Control",
"public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400"
)
.expect("Cache-Control", "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400")
.expect("Vary", /Accept\-Encoding/)
.expect("Surrogate-Key", "sp/42/105")
.expect("Cache-Tag", "sp/42/105")
Expand All @@ -293,10 +265,7 @@ describe("Custom Route Handler", function () {
);
supertest(app)
.get("/static-without-header-footer")
.expect(
"Cache-Control",
"public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400"
)
.expect("Cache-Control", "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400")
.expect("Vary", "Accept-Encoding")
.expect("Surrogate-Key", "sp/42/104")
.expect("Cache-Tag", "sp/42/104")
Expand Down
14 changes: 2 additions & 12 deletions test/integration/isomorphic-handler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,7 @@ describe("Isomorphic Handler", function () {
}),
}
);

supertest(app)
.get("/")
.expect("Content-Type", /html/)
.expect(500)
.then((res) => {
const response = JSON.parse(res.text);
assert.equal('<div data-page-type="not-found">foobar</div>', response.content);
assert.equal(true, response.store.qt.disableIsomorphicComponent);
})
.then(done, done);
supertest(app).get("/").expect(500, done);
});

it("Throws a 500 if loadData and loadErrorData both crash", function (done) {
Expand All @@ -194,7 +184,7 @@ describe("Isomorphic Handler", function () {
}
);

supertest(app).get("/").expect("Content-Type", /html/).expect(500, done);
supertest(app).get("/").expect(500, done);
});

it("Cache headers are set", function (done) {
Expand Down
50 changes: 10 additions & 40 deletions test/integration/url-redirect-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,7 @@ describe("Redirect Routes Handler", function () {
redirectUrls,
}
);
supertest(app)
.get("/moved-permanently-1")
.expect("Location", "/permanent-location-1")
.expect(301, done);
supertest(app).get("/moved-permanently-1").expect("Location", "/permanent-location-1").expect(301, done);
});

it("Redirects all the urls with status code to 302 if redirectUrls is present", function (done) {
Expand All @@ -528,10 +525,7 @@ describe("Redirect Routes Handler", function () {
],
}
);
supertest(app)
.get("/moved-temporarily-1")
.expect("Location", "/temporarily-location-1")
.expect(302, done);
supertest(app).get("/moved-temporarily-1").expect("Location", "/temporarily-location-1").expect(302, done);
});

it("Renders homepage when redirect urls are present", function (done) {
Expand All @@ -555,10 +549,7 @@ describe("Redirect Routes Handler", function () {
.expect(200)
.then((res) => {
const response = JSON.parse(res.text);
assert.equal(
'<div data-page-type="home-page">foobar</div>',
response.content
);
assert.equal('<div data-page-type="home-page">foobar</div>', response.content);
assert.equal("foobar", response.store.qt.data.text);
assert.equal("127.0.0.1", response.store.qt.data.host);
assert.equal("home-page", response.store.qt.pageType);
Expand All @@ -572,10 +563,7 @@ describe("Redirect Routes Handler", function () {
[{ pageType: "story-page", path: "/*" }],
{ redirectUrls: getRedirectUrl }
);
supertest(app)
.get("/moved-permanently-1")
.expect("Location", "/permanent-location-1")
.expect(301, done);
supertest(app).get("/moved-permanently-1").expect("Location", "/permanent-location-1").expect(301, done);
});

it("Should handle Route Parameters redirects properly", function (done) {
Expand All @@ -584,10 +572,7 @@ describe("Redirect Routes Handler", function () {
[{ pageType: "story-page", path: "/*" }],
{ redirectUrls: getRedirectUrl }
);
supertest(app)
.get("/india/news/some-slug")
.expect("Location", "/india/some-slug")
.expect(301, done);
supertest(app).get("/india/news/some-slug").expect("Location", "/india/some-slug").expect(301, done);
});

it("Should handle multiple Route Parameters redirects properly", function (done) {
Expand All @@ -596,10 +581,7 @@ describe("Redirect Routes Handler", function () {
[{ pageType: "story-page", path: "/*" }],
{ redirectUrls: getRedirectUrl }
);
supertest(app)
.get("/india/foo/some-slug/slug")
.expect("Location", "/india/some-slug")
.expect(302, done);
supertest(app).get("/india/foo/some-slug/slug").expect("Location", "/india/some-slug").expect(302, done);
});

it("Should handle interchanging route parameter redirects properly", function (done) {
Expand All @@ -608,10 +590,7 @@ describe("Redirect Routes Handler", function () {
[{ pageType: "story-page", path: "/*" }],
{ redirectUrls: getRedirectUrl }
);
supertest(app)
.get("/foo/something/bar")
.expect("Location", "/bar/something/foo")
.expect(301, done);
supertest(app).get("/foo/something/bar").expect("Location", "/bar/something/foo").expect(301, done);
});

it("Should handle external redirects", function (done) {
Expand All @@ -620,10 +599,7 @@ describe("Redirect Routes Handler", function () {
[{ pageType: "story-page", path: "/*" }],
{ redirectUrls: getRedirectUrl }
);
supertest(app)
.get("/something/new")
.expect("Location", "https://www.google.com/something")
.expect(301, done);
supertest(app).get("/something/new").expect("Location", "https://www.google.com/something").expect(301, done);
});

it("Should handle external redirects with params", function (done) {
Expand All @@ -632,10 +608,7 @@ describe("Redirect Routes Handler", function () {
[{ pageType: "story-page", path: "/*" }],
{ redirectUrls: getRedirectUrl }
);
supertest(app)
.get("/something/new1")
.expect("Location", "https://www.google.com/new1")
.expect(301, done);
supertest(app).get("/something/new1").expect("Location", "https://www.google.com/new1").expect(301, done);
});

it("Should not crash if redirectUrls is not present", function (done) {
Expand All @@ -646,10 +619,7 @@ describe("Redirect Routes Handler", function () {
supertest(app)
.get("/moved-temporarily-1")
.expect("Location", "/temporarily-location-1")
.expect(
"Cache-Control",
"public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400"
)
.expect("Cache-Control", "public,max-age=15,s-maxage=900,stale-while-revalidate=1000,stale-if-error=14400")
.expect("Vary", /Accept\-Encoding/)
.expect("Surrogate-Key", "sp/42/102")
.expect("Cache-Tag", "sp/42/102")
Expand Down