forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move is-archived-version into a function instead of middleware
- Loading branch information
Showing
4 changed files
with
14 additions
and
13 deletions.
There are no files selected for viewing
16 changes: 8 additions & 8 deletions
16
middleware/is-archived-version.js → lib/is-archived-version.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
const patterns = require('../lib/patterns') | ||
const { deprecated } = require('../lib/enterprise-server-releases') | ||
|
||
module.exports = async (req, res, next) => { | ||
module.exports = function isArchivedVersion (req) { | ||
// if this is an assets path, use the referrer | ||
// if this is a docs path, use the req.path | ||
const pathToCheck = patterns.assetPaths.test(req.path) | ||
? req.get('referrer') | ||
: req.path | ||
|
||
// ignore paths that don't have an enterprise version number | ||
if (!(patterns.getEnterpriseVersionNumber.test(pathToCheck) || patterns.getEnterpriseServerNumber.test(pathToCheck))) return next() | ||
if (!(patterns.getEnterpriseVersionNumber.test(pathToCheck) || patterns.getEnterpriseServerNumber.test(pathToCheck))) { | ||
return {} | ||
} | ||
|
||
// extract enterprise version from path, e.g. 2.16 | ||
const requestedVersion = pathToCheck.includes('enterprise-server@') | ||
? pathToCheck.match(patterns.getEnterpriseServerNumber)[1] | ||
: pathToCheck.match(patterns.getEnterpriseVersionNumber)[1] | ||
|
||
// bail if the request version is not deprecated | ||
if (!deprecated.includes(requestedVersion)) return next() | ||
if (!deprecated.includes(requestedVersion)) { | ||
return {} | ||
} | ||
|
||
// attach convenience props | ||
req.isArchivedVersion = true | ||
req.requestedVersion = requestedVersion | ||
|
||
return next() | ||
return { isArchived: true, requestedVersion } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters