Enable more react pages (#19935)
* enable more react landing pages * move nextjs page logic to separate middleware * enable codespaces landing page + fixes * enable /education * enable /admin * use pathToRegexp to match routes for react rendering * run lint * fix: typo in url * update sidebar test
This commit is contained in:
52
middleware/is-next-request.js
Normal file
52
middleware/is-next-request.js
Normal file
@@ -0,0 +1,52 @@
|
||||
const pathToRegexp = require('path-to-regexp')
|
||||
|
||||
const { FEATURE_NEXTJS } = process.env;
|
||||
|
||||
const productIds = [
|
||||
// 'actions',
|
||||
'admin',
|
||||
"billing",
|
||||
"code-security",
|
||||
"codespaces",
|
||||
"communities",
|
||||
"desktop",
|
||||
"developers",
|
||||
"discussions",
|
||||
// 'early-access',
|
||||
"education",
|
||||
// 'github',
|
||||
"graphql",
|
||||
// 'insights',
|
||||
"issues",
|
||||
"organizations",
|
||||
// 'packages',
|
||||
"pages",
|
||||
"rest",
|
||||
"sponsors",
|
||||
];
|
||||
|
||||
const landingPageExp = pathToRegexp('/:locale/:versionId?/:productId')
|
||||
|
||||
module.exports = function isNextRequest(req, res, next) {
|
||||
req.renderWithNextjs = false;
|
||||
|
||||
if (FEATURE_NEXTJS) {
|
||||
if ('nextjs' in req.query) {
|
||||
req.renderWithNextjs = true;
|
||||
} else {
|
||||
// Custom path matching to determine if we should render with nextjs
|
||||
|
||||
// Remove any query string (?...) and/or fragment identifier (#...)
|
||||
const { pathname } = new URL(req.originalUrl, "https://docs.github.com");
|
||||
|
||||
// Should the current path be rendered by NextJS?
|
||||
const landingPageMatch = landingPageExp.exec(pathname)
|
||||
if (landingPageMatch) {
|
||||
const productId = landingPageMatch[3]
|
||||
req.renderWithNextjs = productIds.includes(productId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
};
|
||||
Reference in New Issue
Block a user