@@ -29,23 +29,39 @@ import type { CreateRepositoryRequest } from './client/newOrgRepo.js';
2929
3030const hardcodedApiVersions = [ '2019-10-01' , '2019-02-01' , '2017-09-01' , '2017-03-08' , '2016-12-01' ] ;
3131
32+ const MOST_RECENT_VERSION = hardcodedApiVersions [ 0 ] ;
33+ const CLIENT_ROUTE_PREFIX = '/client' ;
34+
35+ function skipApiVersionCheck ( req : ReposAppRequest , prefixes : string [ ] ) {
36+ for ( const prefix of prefixes ) {
37+ if ( req . path . startsWith ( prefix ) ) {
38+ return true ;
39+ }
40+ }
41+ return false ;
42+ }
43+
3244function isClientRoute ( req : ReposAppRequest ) {
33- const path = req . path . toLowerCase ( ) ;
34- return path . startsWith ( '/client' ) ;
45+ return req . path . startsWith ( CLIENT_ROUTE_PREFIX ) ;
3546}
3647
3748export default function routeApi ( config : SiteConfiguration ) {
3849 if ( ! config ) {
3950 throw CreateError . InvalidParameters ( 'No configuration provided to the API routes' ) ;
4051 }
52+ const companySpecificDeployment = getCompanySpecificDeployment ( ) ;
53+ const skipApiVersionChecksForPrefixes =
54+ companySpecificDeployment ?. routes ?. api ?. skipApiVersionChecksForPrefixes || [ ] ;
55+ const combinedSkipVersionPrefixes = [ CLIENT_ROUTE_PREFIX , ...skipApiVersionChecksForPrefixes ] ;
4156
4257 router . use ( '/webhook' , apiWebhook ) ;
4358
4459 router . use ( ( req : ReposApiRequest , res : Response , next : NextFunction ) => {
45- if ( isClientRoute ( req ) ) {
60+ if ( skipApiVersionCheck ( req , combinedSkipVersionPrefixes ) ) {
4661 // The frontend client routes are hooked into Express after
4762 // the session middleware. The client route does not require
48- // an API version.
63+ // an API version. Also, some APIs do not require a version.
64+ req . apiVersion = MOST_RECENT_VERSION ;
4965 return next ( ) ;
5066 }
5167 const apiVersion = ( req . query [ 'api-version' ] || req . headers [ 'api-version' ] ) as string ;
0 commit comments