@@ -41,34 +41,35 @@ function _fetch($loop, string $method, ...$opts) : Promise
4141const _credentials = 'Chemem \\Fauxton \\Http \\_credentials ' ;
4242function _credentials (string $ config ) : array
4343{
44- $ let = PM \letIn (array ('username ' , 'password ' , 'local ' ), json_decode ($ config , true ));
44+ $ let = PM \letIn (array ('username ' , 'password ' , 'host ' , ' local ' ), json_decode ($ config , true ));
4545
46- return $ let (array ('username ' , 'password ' , 'local ' ), function (array $ username , array $ password , bool $ local ) {
46+ return $ let (array ('username ' , 'password ' , 'host ' , ' local ' ), function (array $ username , array $ password, string $ host , bool $ local ) {
4747 $ credentials = A \curry (A \pluck);
4848
4949 return A \extend (
5050 array ($ local ),
5151 array ($ local ? $ credentials ($ username )('local ' ) : $ credentials ($ username )('cloudant ' )),
52- array ($ local ? $ credentials ($ password )('local ' ) : $ credentials ($ password )('cloudant ' ))
52+ array ($ local ? $ credentials ($ password )('local ' ) : $ credentials ($ password )('cloudant ' )),
53+ array ($ local ? '' : $ host )
5354 );
5455 });
5556}
5657
5758const _url = 'Chemem \\Fauxton \\Http \\_url ' ;
5859function _url (array $ credentials , array $ opts ) : string
5960{
60- $ cred = array ('local ' , 'user ' , 'pass ' );
61+ $ cred = array ('local ' , 'user ' , 'pass ' , ' host ' );
6162 $ let = PM \letIn ($ cred , $ credentials );
6263
63- return $ let ($ cred , function (bool $ local , string $ user , string $ pass ) use ($ opts ) {
64+ return $ let ($ cred , function (bool $ local , string $ user , string $ pass, string $ host ) use ($ opts ) {
6465 $ frag = A \head ($ opts );
6566 $ fragments = A \compose (
6667 _urlFragments ($ opts , $ local ),
6768 A \partial ('str_replace ' , array_keys ($ frag ), array_values ($ frag )),
6869 A \partialRight ('rtrim ' , '? ' )
6970 );
7071
71- return A \concat ('/ ' , _schemeHost ($ local , $ user , $ pass ), $ fragments (State::COUCH_ACTIONS ));
72+ return A \concat ('/ ' , _schemeHost ($ local , $ user , $ pass, $ host ), $ fragments (State::COUCH_ACTIONS ));
7273 });
7374}
7475
@@ -82,13 +83,13 @@ function _urlFragments(array $opts, bool $local) : callable
8283}
8384
8485const _schemeHost = 'Chemem \\Fauxton \\Http \\_schemeHost ' ;
85- function _schemeHost (bool $ local , string $ user , string $ pass ) : string
86+ function _schemeHost (bool $ local , string $ user , string $ pass, string $ host ) : string
8687{
8788 return $ local ?
8889 State::COUCH_URI_LOCAL :
8990 str_replace (
9091 array ('{cloudantUser} ' , '{cloudantPass} ' , '{cloudantHost} ' ),
91- array ($ user , $ pass , A \concat ( ' . ' , $ user , ' cloudant ' , ' com ' ) ),
92+ array ($ user , $ pass , $ host ),
9293 State::COUCH_URI_CLOUDANT
9394 );
9495}
0 commit comments