@@ -4,6 +4,7 @@ const EventEmitter = require('events');
44const InfluxQL = require ( 'influx-ql' ) ;
55const request = require ( 'superagent' ) ;
66const _ = require ( 'lodash' ) ;
7+ const querystring = require ( 'querystring' ) ;
78
89const Influx = require ( './influx' ) ;
910const debug = require ( './debug' ) ;
@@ -84,13 +85,28 @@ class Client extends EventEmitter {
8485 port : parseInt ( arr [ 1 ] , 10 ) ,
8586 } ;
8687 } ) ;
87- opts . database = result [ 4 ] || '' ;
88+ const db = result [ 4 ] || '' ;
89+ const queryIndex = db . indexOf ( '?' ) ;
90+ let query = '' ;
91+ if ( queryIndex === - 1 ) {
92+ opts . database = db ;
93+ } else {
94+ opts . database = db . substring ( 0 , queryIndex ) ;
95+ query = db . substr ( queryIndex + 1 ) ;
96+ }
8897 /* istanbul ignore else */
8998 if ( result [ 2 ] ) {
9099 const authInfos = result [ 2 ] . substring ( 0 , result [ 2 ] . length - 1 ) . split (
91100 ':' ) ;
92101 opts . username = authInfos [ 0 ] ;
93102 opts . password = authInfos [ 1 ] ;
103+ // 根据query配置,判断使用哪种认证方式
104+ if ( query ) {
105+ const queryInfo = querystring . parse ( query ) ;
106+ if ( queryInfo . auth ) {
107+ opts . authType = queryInfo . auth ;
108+ }
109+ }
94110 }
95111 debug ( 'init options:%j' , opts ) ;
96112 const internalData = internal ( this ) ;
@@ -115,8 +131,8 @@ class Client extends EventEmitter {
115131 */
116132 startHealthCheck ( ping , interval ) {
117133 const defaultPing = ( backend ) => {
118- const url = `${ backend . protocol || 'http' } ://${ backend . host } :${ backend . port || 80 } /ping` ;
119- return request . get ( url ) . timeout ( 1000 ) ;
134+ const pingUrl = `${ backend . protocol || 'http' } ://${ backend . host } :${ backend . port || 80 } /ping` ;
135+ return request . get ( pingUrl ) . timeout ( 1000 ) ;
120136 } ;
121137 const pingFn = _ . isNumber ( ping ) ? null : ping ;
122138 const ms = _ . isNumber ( ping ) ? ping : interval ;
0 commit comments