@@ -7,6 +7,35 @@ import { getErrorMessage } from "../util";
77
88import { getAddressString , ProxyInfo , Registry } from "./types" ;
99
10+ /** Represents registry-specific connection test configurations. */
11+ export interface ConnectionTestConfig {
12+ /** An optional path to append to the end of the base url. */
13+ path ?: string ;
14+ }
15+
16+ /** A partial mapping of registry types to extra connection test configurations. */
17+ export const connectionTestConfig : Partial <
18+ Record < string , ConnectionTestConfig >
19+ > = {
20+ nuget_feed : { path : "v3/index.json" } ,
21+ } ;
22+
23+ /**
24+ * Applies the registry-specific check configuration to the base URL, if any and applicable.
25+ */
26+ export function makeTestUrl (
27+ config : ConnectionTestConfig | undefined ,
28+ base : URL ,
29+ ) : URL {
30+ if ( config ?. path === undefined ) {
31+ return base ;
32+ }
33+ if ( base . pathname . endsWith ( config . path ) ) {
34+ return base ;
35+ }
36+ return new URL ( config . path , base ) ;
37+ }
38+
1039export class ReachabilityError extends Error {
1140 constructor ( public readonly statusCode ?: number | undefined ) {
1241 super ( ) ;
@@ -92,6 +121,7 @@ export async function checkConnections(
92121 }
93122
94123 for ( const registry of proxy . registries ) {
124+ const config = connectionTestConfig [ registry . type ] ;
95125 const address = getAddressString ( registry ) ;
96126 const url = URL . parse ( address ) ;
97127
@@ -102,9 +132,11 @@ export async function checkConnections(
102132 continue ;
103133 }
104134
135+ const testUrl = makeTestUrl ( config , url ) ;
136+
105137 try {
106138 logger . debug ( `Testing connection to ${ url } ...` ) ;
107- const statusCode = await backend . checkConnection ( url ) ;
139+ const statusCode = await backend . checkConnection ( testUrl ) ;
108140
109141 logger . info ( `Successfully tested connection to ${ url } (${ statusCode } )` ) ;
110142 result . add ( registry ) ;
0 commit comments