diff --git a/package-lock.json b/package-lock.json index acc1ff2f..93663c1e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@quintype/framework", - "version": "7.25.0", + "version": "7.25.1-fix-ampstories-404.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@quintype/framework", - "version": "7.25.0", + "version": "7.25.1-fix-ampstories-404.2", "license": "ISC", "dependencies": { "@ampproject/toolbox-optimizer": "2.8.3", diff --git a/package.json b/package.json index 49f82d21..bb665539 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/server/amp/handlers/story-page.js b/server/amp/handlers/story-page.js index a1bfe3f6..b92e84f9 100644 --- a/server/amp/handlers/story-page.js +++ b/server/amp/handlers/story-page.js @@ -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; @@ -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, "")