@@ -7,6 +7,17 @@ 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+ const connectionTestConfig : Partial < Record < string , ConnectionTestConfig > > = {
18+ nuget_feed : { path : "/v3/index.json" } ,
19+ } ;
20+
1021export class ReachabilityError extends Error {
1122 constructor ( public readonly statusCode ?: number | undefined ) {
1223 super ( ) ;
@@ -92,6 +103,7 @@ export async function checkConnections(
92103 }
93104
94105 for ( const registry of proxy . registries ) {
106+ const config = connectionTestConfig [ registry . type ] ;
95107 const address = getAddressString ( registry ) ;
96108 const url = URL . parse ( address ) ;
97109
@@ -102,18 +114,25 @@ export async function checkConnections(
102114 continue ;
103115 }
104116
117+ const testUrl =
118+ config ?. path === undefined ? url : new URL ( config . path , url ) ;
119+
105120 try {
106- logger . debug ( `Testing connection to ${ url } ...` ) ;
107- const statusCode = await backend . checkConnection ( url ) ;
121+ logger . debug ( `Testing connection to ${ testUrl } ...` ) ;
122+ const statusCode = await backend . checkConnection ( testUrl ) ;
108123
109- logger . info ( `Successfully tested connection to ${ url } (${ statusCode } )` ) ;
124+ logger . info (
125+ `Successfully tested connection to ${ testUrl } (${ statusCode } )` ,
126+ ) ;
110127 result . add ( registry ) ;
111128 } catch ( e ) {
112129 if ( e instanceof ReachabilityError && e . statusCode !== undefined ) {
113- logger . info ( `Connection test to ${ url } failed. (${ e . statusCode } )` ) ;
130+ logger . info (
131+ `Connection test to ${ testUrl } failed. (${ e . statusCode } )` ,
132+ ) ;
114133 } else {
115134 logger . warning (
116- `Connection test to ${ url } failed: ${ getErrorMessage ( e ) } ` ,
135+ `Connection test to ${ testUrl } failed: ${ getErrorMessage ( e ) } ` ,
117136 ) ;
118137 }
119138 }
0 commit comments