@@ -144,10 +144,17 @@ export interface INonceEndpointOpts extends ISingleEndpointOpts {
144144 baseUrl : string | URL
145145}
146146
147+ export enum WellKnownHostLocation {
148+ AT_CONTEXT_PATH = 'AT_CONTEXT_PATH' ,
149+ AT_ROOT_PATH = 'AT_ROOT_PATH' ,
150+ AT_BOTH = 'AT_BOTH'
151+ }
152+
147153export interface IOID4VCIServerOpts extends HasEndpointOpts {
148154 asClientOpts ?: ClientMetadata
149155 endpointOpts ?: IOID4VCIEndpointOpts
150156 baseUrl ?: string
157+ wellKnownHostLocation ?: WellKnownHostLocation
151158}
152159
153160export class OID4VCIServer {
@@ -159,6 +166,7 @@ export class OID4VCIServer {
159166 // private readonly _server?: http.Server
160167 private readonly _router : express . Router
161168 private readonly _asClientOpts ?: ClientMetadata
169+ private readonly _wellknownHostLocation ?: WellKnownHostLocation
162170
163171 constructor (
164172 expressSupport : ExpressSupport ,
@@ -173,9 +181,23 @@ export class OID4VCIServer {
173181 this . _issuer = opts ?. issuer ? opts . issuer : buildVCIFromEnvironment ( )
174182 this . _asClientOpts =
175183 opts . asClientOpts || this . _issuer . asClientOpts ? ( { ...opts . asClientOpts , ...this . _issuer . asClientOpts } as ClientMetadata ) : undefined
176-
184+ this . _wellknownHostLocation = opts ?. wellKnownHostLocation ?? ( process . env . WELLKNOWN_HOST_LOCATION as WellKnownHostLocation ) ?? WellKnownHostLocation . AT_BOTH
177185 pushedAuthorizationEndpoint ( this . router , this . issuer , this . authRequestsData )
178- getMetadataEndpoints ( this . router , this . issuer )
186+
187+ // Create root router for alternative .well-known endpoints if needed
188+ const basePath = getBasePath ( this . baseUrl )
189+ let rootRouter : express . Router | undefined
190+ if ( basePath && basePath !== '/' && ( this . wellknownHostLocation == WellKnownHostLocation . AT_ROOT_PATH || this . wellknownHostLocation == WellKnownHostLocation . AT_BOTH ) ) {
191+ rootRouter = express . Router ( )
192+ this . _app . use ( '/' , rootRouter )
193+ }
194+
195+ getMetadataEndpoints ( this . router , this . issuer , {
196+ rootRouter,
197+ basePath,
198+ wellKnownHostLocation : this . wellknownHostLocation
199+ } )
200+
179201 let issuerPayloadPath : string | undefined
180202 if ( this . isGetIssuePayloadEndpointEnabled ( opts ?. endpointOpts ?. getIssuePayloadOpts ) ) {
181203 issuerPayloadPath = getCredentialOfferReferenceEndpoint ( this . router , this . issuer , {
@@ -227,7 +249,7 @@ export class OID4VCIServer {
227249 baseUrl : this . baseUrl ,
228250 } )
229251 }
230- this . _app . use ( getBasePath ( this . baseUrl ) , this . _router )
252+ this . _app . use ( basePath , this . _router )
231253 }
232254
233255 public get app ( ) : Express {
@@ -300,4 +322,8 @@ export class OID4VCIServer {
300322 get baseUrl ( ) : URL {
301323 return this . _baseUrl
302324 }
325+
326+ get wellknownHostLocation ( ) : WellKnownHostLocation | undefined {
327+ return this . _wellknownHostLocation
328+ }
303329}
0 commit comments