@quintype/framework 7.7.4 → 7.8.0-prerender-query-param.0
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/CHANGELOG.md
CHANGED
|
@@ -2,15 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
-
### [7.7.4](https://github.com/quintype/quintype-node-framework/compare/v7.7.3...v7.7.4) (2022-07-13)
|
|
6
|
-
|
|
7
|
-
### [7.7.3](https://github.com/quintype/quintype-node-framework/compare/v7.7.2...v7.7.3) (2022-07-13)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
### Bug Fixes
|
|
11
|
-
|
|
12
|
-
* remove prerender query param after the prerender check ([#314](https://github.com/quintype/quintype-node-framework/issues/314)) ([94eac28](https://github.com/quintype/quintype-node-framework/commit/94eac28bfd04483cc665c5ce4d2fc8768c84a31b))
|
|
13
|
-
|
|
14
5
|
### [7.7.2](https://github.com/quintype/quintype-node-framework/compare/v7.7.1...v7.7.2) (2022-07-08)
|
|
15
6
|
|
|
16
7
|
### [7.7.1](https://github.com/quintype/quintype-node-framework/compare/v7.7.0...v7.7.1) (2022-07-06)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quintype/framework",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.8.0-prerender-query-param.0",
|
|
4
4
|
"description": "Libraries to help build Quintype Node.js apps",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"engines": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"homepage": "https://github.com/quintype/quintype-node-framework#readme",
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@ampproject/toolbox-optimizer": "2.8.3",
|
|
34
|
-
"@quintype/amp": "^2.4.
|
|
34
|
+
"@quintype/amp": "^2.4.23",
|
|
35
35
|
"@quintype/backend": "^2.3.1",
|
|
36
36
|
"@quintype/components": "^3.0.0",
|
|
37
37
|
"@quintype/prerender-node": "^3.2.24",
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
const { ampStoryPageHandler } = require("./story-page");
|
|
2
2
|
const { storyPageInfiniteScrollHandler } = require("./infinite-scroll");
|
|
3
|
+
const { bookendHandler } = require("./visual-stories-bookend");
|
|
3
4
|
|
|
4
5
|
module.exports = {
|
|
5
6
|
ampStoryPageHandler,
|
|
6
7
|
storyPageInfiniteScrollHandler,
|
|
8
|
+
bookendHandler,
|
|
7
9
|
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const get = require("lodash/get");
|
|
2
|
+
|
|
3
|
+
function getStoryUrl(story, config) {
|
|
4
|
+
if (get(story, ["story-template"]) === "news-elsewhere") {
|
|
5
|
+
return get(story, ["metadata", "reference-url"], "");
|
|
6
|
+
}
|
|
7
|
+
return `${config["sketches-host"]}/${story.slug}`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async function bookendHandler(req, res, next, { config, client, sMaxAge = "900" }) {
|
|
11
|
+
const { storyId, sectionId } = req.query;
|
|
12
|
+
if (!storyId || !sectionId) {
|
|
13
|
+
res.status(400).json({
|
|
14
|
+
error: {
|
|
15
|
+
message: "Please provide 'storyId' and 'sectionId' query parameters",
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const relatedStoriesResponse = await client.getRelatedStories(storyId, sectionId);
|
|
22
|
+
const relatedStories = relatedStoriesResponse["related-stories"];
|
|
23
|
+
|
|
24
|
+
if (!relatedStories.length) {
|
|
25
|
+
res.status(404).json({ error: { message: "Not Found" } });
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const fbAppId = get(config, ["public-integrations", "facebook", "app-id"], "");
|
|
30
|
+
|
|
31
|
+
const jsonPayLoad = {
|
|
32
|
+
bookendVersion: "v1.0",
|
|
33
|
+
shareProviders: [
|
|
34
|
+
"twitter",
|
|
35
|
+
"email",
|
|
36
|
+
{
|
|
37
|
+
provider: "facebook",
|
|
38
|
+
app_id: fbAppId,
|
|
39
|
+
},
|
|
40
|
+
"whatsapp",
|
|
41
|
+
"linkedin",
|
|
42
|
+
"gplus",
|
|
43
|
+
],
|
|
44
|
+
components: [].concat(
|
|
45
|
+
[
|
|
46
|
+
{
|
|
47
|
+
type: "heading",
|
|
48
|
+
text: "More to read",
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
relatedStories.map((story) => ({
|
|
52
|
+
type: "small",
|
|
53
|
+
title: `${story.headline}`,
|
|
54
|
+
image: `${config["cdn-name"]}${story["hero-image-s3-key"]}?w=480&auto=format&compress`,
|
|
55
|
+
url: getStoryUrl(story, config),
|
|
56
|
+
})),
|
|
57
|
+
[
|
|
58
|
+
{
|
|
59
|
+
type: "cta-link",
|
|
60
|
+
links: [
|
|
61
|
+
{
|
|
62
|
+
text: "More stories",
|
|
63
|
+
url: `${config["sketches-host"]}`,
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
]
|
|
68
|
+
),
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
res.header("Cache-Control", `public,max-age=15,s-maxage=${sMaxAge},stale-while-revalidate=1000,stale-if-error=14400`);
|
|
72
|
+
res.header("Vary", "Accept-Encoding");
|
|
73
|
+
|
|
74
|
+
res.json(jsonPayLoad);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
module.exports = { bookendHandler };
|
package/server/routes.js
CHANGED
|
@@ -345,8 +345,10 @@ exports.isomorphicRoutes = function isomorphicRoutes(
|
|
|
345
345
|
if (prerenderServiceUrl) {
|
|
346
346
|
app.use((req, res, next) => {
|
|
347
347
|
if (req.query.prerender) {
|
|
348
|
+
delete req.query.prerender;
|
|
348
349
|
try {
|
|
349
350
|
// eslint-disable-next-line global-require
|
|
351
|
+
prerender.set("protocol", "https");
|
|
350
352
|
prerender.set("prerenderServiceUrl", prerenderServiceUrl)(req, res, next);
|
|
351
353
|
} catch (e) {
|
|
352
354
|
logError(e);
|
|
@@ -626,9 +628,10 @@ exports.mountQuintypeAt = function (app, mountAt) {
|
|
|
626
628
|
*
|
|
627
629
|
*/
|
|
628
630
|
exports.ampRoutes = (app, opts = {}) => {
|
|
629
|
-
const { ampStoryPageHandler, storyPageInfiniteScrollHandler } = require("./amp/handlers");
|
|
631
|
+
const { ampStoryPageHandler, storyPageInfiniteScrollHandler, bookendHandler } = require("./amp/handlers");
|
|
630
632
|
|
|
631
633
|
getWithConfig(app, "/amp/story/*", ampStoryPageHandler, opts);
|
|
632
634
|
getWithConfig(app, "/amp/api/v1/amp-infinite-scroll", storyPageInfiniteScrollHandler, opts);
|
|
635
|
+
getWithConfig(app, "/amp/api/v1/bookend.json", bookendHandler, opts);
|
|
633
636
|
getWithConfig(app, "/ampstories/*", ampStoryPageHandler, { ...opts, isVisualStory: true });
|
|
634
637
|
};
|
|
@@ -446,3 +446,41 @@ describe("Amp infinite scroll handler", () => {
|
|
|
446
446
|
});
|
|
447
447
|
});
|
|
448
448
|
});
|
|
449
|
+
|
|
450
|
+
describe("Amp visual stories bookend handler", () => {
|
|
451
|
+
it("returns the bookend if there are related stories", function (done) {
|
|
452
|
+
const app = createApp({
|
|
453
|
+
clientStub: getClientStubWithRelatedStories([{ headline: "foo" }]),
|
|
454
|
+
});
|
|
455
|
+
supertest(app)
|
|
456
|
+
.get("/amp/api/v1/bookend.json?storyId=111§ionId=222")
|
|
457
|
+
.expect("Content-Type", /json/)
|
|
458
|
+
.expect("Cache-Control", /public/)
|
|
459
|
+
.expect(200)
|
|
460
|
+
.then((res) => {
|
|
461
|
+
const response = JSON.parse(res.text);
|
|
462
|
+
assert.equal("v1.0", response.bookendVersion);
|
|
463
|
+
assert.equal(3, response.components.length);
|
|
464
|
+
assert.equal("foo", response.components[1].title);
|
|
465
|
+
})
|
|
466
|
+
.then(() => done());
|
|
467
|
+
});
|
|
468
|
+
it("returns a 404 if there are no related stories", (done) => {
|
|
469
|
+
const app = createApp({ clientStub: getClientStubWithRelatedStories([]) });
|
|
470
|
+
supertest(app)
|
|
471
|
+
.get("/amp/api/v1/bookend.json?storyId=111§ionId=222")
|
|
472
|
+
.expect("Content-Type", /json/)
|
|
473
|
+
.expect(404)
|
|
474
|
+
.then(() => done());
|
|
475
|
+
});
|
|
476
|
+
it("returns a 400 if 'storyId' and 'sectionId' query params aren't passed", (done) => {
|
|
477
|
+
const app = createApp({
|
|
478
|
+
clientStub: getClientStubWithRelatedStories([{ headline: "foo" }]),
|
|
479
|
+
});
|
|
480
|
+
supertest(app)
|
|
481
|
+
.get("/amp/api/v1/bookend.json")
|
|
482
|
+
.expect("Content-Type", /json/)
|
|
483
|
+
.expect(400)
|
|
484
|
+
.then(() => done());
|
|
485
|
+
});
|
|
486
|
+
});
|