Unverified Commit e52508fb authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Consolidate traditional and AMP rendering methods (#6506)

* Format a few documents

* Drop `renderToAMP` and `renderToAMPHTML`
parent 494889ac
...@@ -204,12 +204,7 @@ export default class Server { ...@@ -204,12 +204,7 @@ export default class Server {
throw new Error('pathname is undefined') throw new Error('pathname is undefined')
} }
// Currently, we will render amp even if the user passes `?amp=0`.
if (this.nextConfig.experimental.amp && query.amp) {
await this.renderToAMP(req, res, pathname, query, parsedUrl)
} else {
await this.render(req, res, pathname, query, parsedUrl) await this.render(req, res, pathname, query, parsedUrl)
}
}, },
}) })
} }
...@@ -269,7 +264,9 @@ export default class Server { ...@@ -269,7 +264,9 @@ export default class Server {
return this.render404(req, res, parsedUrl) return this.render404(req, res, parsedUrl)
} }
const html = await this.renderToHTML(req, res, pathname, query) const html = await this.renderToHTML(req, res, pathname, query, {
amphtml: query.amp && this.nextConfig.experimental.amp,
})
// Request was ended by the user // Request was ended by the user
if (html === null) { if (html === null) {
return return
...@@ -281,37 +278,6 @@ export default class Server { ...@@ -281,37 +278,6 @@ export default class Server {
return this.sendHTML(req, res, html) return this.sendHTML(req, res, html)
} }
public async renderToAMP(
req: IncomingMessage,
res: ServerResponse,
pathname: string,
query: ParsedUrlQuery = {},
parsedUrl?: UrlWithParsedQuery,
): Promise<void> {
if (!this.nextConfig.experimental.amp) {
throw new Error('"experimental.amp" is not enabled in "next.config.js"')
}
const url: any = req.url
if (isInternalUrl(url)) {
return this.handleRequest(req, res, parsedUrl)
}
if (isBlockedPage(pathname)) {
return this.render404(req, res, parsedUrl)
}
const html = await this.renderToAMPHTML(req, res, pathname, query)
// Request was ended by the user
if (html === null) {
return
}
if (this.nextConfig.poweredByHeader) {
res.setHeader('X-Powered-By', 'Next.js ' + process.env.NEXT_VERSION)
}
return this.sendHTML(req, res, html)
}
private async renderToHTMLWithComponents( private async renderToHTMLWithComponents(
req: IncomingMessage, req: IncomingMessage,
res: ServerResponse, res: ServerResponse,
...@@ -323,18 +289,6 @@ export default class Server { ...@@ -323,18 +289,6 @@ export default class Server {
return renderToHTML(req, res, pathname, query, { ...result, ...opts }) return renderToHTML(req, res, pathname, query, { ...result, ...opts })
} }
public async renderToAMPHTML(
req: IncomingMessage,
res: ServerResponse,
pathname: string,
query: ParsedUrlQuery = {},
): Promise<string | null> {
if (!this.nextConfig.experimental.amp) {
throw new Error('"experimental.amp" is not enabled in "next.config.js"')
}
return this.renderToHTML(req, res, pathname, query, { amphtml: true })
}
public async renderToHTML( public async renderToHTML(
req: IncomingMessage, req: IncomingMessage,
res: ServerResponse, res: ServerResponse,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment