-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
31 lines (28 loc) · 823 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var nano = require('nano'),
request = require('browser-request'),
parse = require('url').parse;
module.exports = self.nano = function (cfg) {
var url;
if (typeof cfg === 'string') {
cfg = {url: cfg};
}
url = parse(cfg.url);
if (url.auth) {
cfg.auth = {
username: url.auth.split(':')[0],
password: url.auth.split(':')[1]
};
}
cfg.url = [url.protocol, '//', url.host].join('');
cfg.request = function (req, callback) {
if (cfg.cors) {
req.withCredentials = true;
}
if (cfg.auth) {
req.authorization = true;
req.auth = cfg.auth;
}
request(req, callback || function () {}); // browser-request throws error on undefined callback
};
return nano(cfg);
};