Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(visual-stories): visual stories throwing 404 #417

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.25.0",
"version": "7.25.1-fix-ampstories-404.2",
"description": "Libraries to help build Quintype Node.js apps",
"main": "index.js",
"engines": {
Expand Down
12 changes: 7 additions & 5 deletions server/amp/handlers/story-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ async function ampStoryPageHandler(
) {
try {
const opts = cloneDeep(rest);
const isCorrectAmpPath = req.path.startsWith(`${getAmpPageBasePath(opts, config)}/`);
if (!isCorrectAmpPath) {
return next();
}
const isCorrectAmpPath = isVisualStory
? req.path.startsWith(`/ampstories`)
: req.path.startsWith(`${getAmpPageBasePath(opts, config)}/`);

if (!isCorrectAmpPath) return next();

const redirectUrls = opts && opts.redirectUrls;
const getEnableAmp = get(opts, ["enableAmp"], true);
const enableAmp = typeof getEnableAmp === "function" ? opts.enableAmp(config) : getEnableAmp;
Expand All @@ -55,7 +57,7 @@ async function ampStoryPageHandler(
const story = await Story.getStoryBySlug(client, req.params["0"]);
const isAmpDisabled = get(story, ["metadata", "story-attributes", "disable-amp-for-single-story", "0"], "false");

if ((!isVisualStory && !enableAmp) || isAmpDisabled === "true") {
if (!isVisualStory && (!enableAmp || isAmpDisabled === "true")) {
const ampPageBasePath = getAmpPageBasePath(opts, config);
const redirectUrl = `/${req.params[0]}`.startsWith(ampPageBasePath)
? `/${req.params[0]}`.replace(ampPageBasePath, "")
Expand Down