Skip to content

Commit

Permalink
Fix amphtml link rel not respecting basePath (#15949)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
amiralies and kodiakhq[bot] authored Aug 8, 2020
1 parent d8edb2e commit 4b6e9a4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/next/next-server/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ function assignDefaults(userConfig: { [key: string]: any }) {
if (result.assetPrefix === '') {
result.assetPrefix = result.basePath
}

if (result.amp.canonicalBase === '') {
result.amp.canonicalBase = result.basePath
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/integration/basepath/pages/amp-hybrid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const config = { amp: 'hybrid' }

export default () => <p>Hello amp</p>
14 changes: 14 additions & 0 deletions test/integration/basepath/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,13 @@ describe('basePath development', () => {
})
})
})

it('should respect basePath in amphtml link rel', async () => {
const html = await renderViaHTTP(context.appPort, '/docs/amp-hybrid')
const $ = cheerio.load(html)
const expectedAmpHtmlUrl = '/docs/amp-hybrid?amp=1'
expect($('link[rel=amphtml]').first().attr('href')).toBe(expectedAmpHtmlUrl)
})
})

describe('basePath production', () => {
Expand All @@ -1053,6 +1060,13 @@ describe('basePath production', () => {
afterAll(() => stopApp(server))

runTests(context)

it('should respect basePath in amphtml link rel', async () => {
const html = await renderViaHTTP(context.appPort, '/docs/amp-hybrid')
const $ = cheerio.load(html)
const expectedAmpHtmlUrl = '/docs/amp-hybrid.amp'
expect($('link[rel=amphtml]').first().attr('href')).toBe(expectedAmpHtmlUrl)
})
})

describe('basePath serverless', () => {
Expand Down

0 comments on commit 4b6e9a4

Please sign in to comment.