File tree 4 files changed +14
-6
lines changed
4 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -1411,10 +1411,12 @@ export interface ConnectionOptions {
1411
1411
noAsyncTraces ?: boolean ;
1412
1412
1413
1413
/**
1414
- * When true, the connect function will remove any name resolution provided by
1415
- * the transport. In some environments (browsers) this is a no-op option.
1414
+ * When false, the connect function will not perform any hostname resolution. Note that
1415
+ * by default this option will be true if the client supports hostname resolution.
1416
+ * Note that on clients that don't supported (mainly the websocket client, setting this
1417
+ * option to true, will throw an exception as this option is not available.
1416
1418
*/
1417
- noResolve ?: boolean ;
1419
+ resolve ?: boolean ;
1418
1420
}
1419
1421
1420
1422
/**
Original file line number Diff line number Diff line change @@ -135,6 +135,12 @@ export function parseOptions(opts?: ConnectionOptions): ConnectionOptions {
135
135
}
136
136
}
137
137
138
+ // if not set - we set it
139
+ if ( options . resolve === undefined ) {
140
+ // set a default based on whether the client can resolve or not
141
+ options . resolve = typeof getResolveFn ( ) === "function" ;
142
+ }
143
+
138
144
if ( options . resolve ) {
139
145
if ( typeof getResolveFn ( ) !== "function" ) {
140
146
throw new NatsError (
Original file line number Diff line number Diff line change @@ -594,8 +594,8 @@ export class ProtocolHandler implements Dispatcher<ParserEvent> {
594
594
}
595
595
596
596
async _doDial ( srv : Server ) : Promise < void > {
597
- const resolve = this . options . noResolve !== true ;
598
- const alts = this . options . noResolve === true ? [ srv ] : await srv . resolve ( {
597
+ const { resolve } = this . options ;
598
+ const alts = await srv . resolve ( {
599
599
fn : getResolveFn ( ) ,
600
600
debug : this . options . debug ,
601
601
randomize : ! this . options . noRandomize ,
Original file line number Diff line number Diff line change @@ -1437,7 +1437,7 @@ Deno.test("basics - noResolve", async () => {
1437
1437
const nci = await connect ( {
1438
1438
servers : "connect.ngs.global" ,
1439
1439
authenticator : jwtAuthenticator ( token ) ,
1440
- noResolve : true ,
1440
+ resolve : false ,
1441
1441
} ) as NatsConnectionImpl ;
1442
1442
1443
1443
const srv = nci . protocol . servers . getCurrentServer ( ) ;
You can’t perform that action at this time.
0 commit comments