(req, res)
| 33 | } |
| 34 | |
| 35 | export default async function renderPage(req, res) { |
| 36 | const { context } = req |
| 37 | |
| 38 | // This is a contextualizing the request so that when this `req` is |
| 39 | // ultimately passed into the `Error.getInitialProps` function, |
| 40 | // which NextJS executes at runtime on errors, so that we can |
| 41 | // from there send the error to Failbot. |
| 42 | req.FailBot = FailBot |
| 43 | |
| 44 | const { page } = context |
| 45 | const path = req.pagePath || req.path |
| 46 | |
| 47 | // render a 404 page |
| 48 | if (!page) { |
| 49 | if (process.env.NODE_ENV !== 'test' && context.redirectNotFound) { |
| 50 | console.error( |
| 51 | `\nTried to redirect to ${context.redirectNotFound}, but that page was not found.\n` |
| 52 | ) |
| 53 | } |
| 54 | return nextApp.render404(req, res) |
| 55 | } |
| 56 | |
| 57 | // Just finish fast without all the details like Content-Length |
| 58 | if (req.method === 'HEAD') { |
| 59 | return res.status(200).send('') |
| 60 | } |
| 61 | |
| 62 | // Updating the Last-Modified header for substantive changes on a page for engineering |
| 63 | // Docs Engineering Issue #945 |
| 64 | if (page.effectiveDate) { |
| 65 | // Note that if a page has an invalidate `effectiveDate` string value, |
| 66 | // it would be caught prior to this usage and ultimately lead to |
| 67 | // 500 error. |
| 68 | res.setHeader('Last-Modified', new Date(page.effectiveDate).toUTCString()) |
| 69 | } |
| 70 | |
| 71 | // collect URLs for variants of this page in all languages |
| 72 | page.languageVariants = Page.getLanguageVariants(path) |
| 73 | |
| 74 | // Stop processing if the connection was already dropped |
| 75 | if (isConnectionDropped(req, res)) return |
| 76 | |
| 77 | req.context.renderedPage = await buildRenderedPage(req) |
| 78 | req.context.miniTocItems = await buildMiniTocItems(req) |
| 79 | |
| 80 | // Stop processing if the connection was already dropped |
| 81 | if (isConnectionDropped(req, res)) return |
| 82 | |
| 83 | // Create string for <title> tag |
| 84 | page.fullTitle = page.title |
| 85 | |
| 86 | // add localized ` - GitHub Docs` suffix to <title> tag (except for the homepage) |
| 87 | if (!patterns.homepagePath.test(path)) { |
| 88 | if ( |
| 89 | req.context.currentVersion === 'free-pro-team@latest' || |
| 90 | !allVersions[req.context.currentVersion] |
| 91 | ) { |
| 92 | page.fullTitle += ' - ' + context.site.data.ui.header.github_docs |
nothing calls this directly
no test coverage detected