* 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
53 lines
1.2 KiB
JavaScript
53 lines
1.2 KiB
JavaScript
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();
|
|
};
|