-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
61 lines (50 loc) · 1.38 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict';
var async = require('async');
var request = require('request');
var JXT = require('jxt').createRegistry();
JXT.use(require('./lib/xrd'));
module.exports = function (opts, cb) {
if (typeof opts === 'string') {
opts = {host: opts};
}
var config = {
ssl: true,
json: true,
xrd: true
};
for (var prop in opts) {
config[prop] = opts[prop];
}
var scheme = config.ssl ? 'https://' : 'http://';
async.parallel([
function (done) {
request(scheme + config.host + '/.well-known/host-meta.json', function (err, req, body) {
if (err) {
return done(null);
}
var data;
try {
data = JSON.parse(body);
} catch (e) {
data = null;
}
return done(data);
});
},
function (done) {
request(scheme + config.host + '/.well-known/host-meta', function (err, req, body) {
if (err) {
return done(null);
}
var xrd = JXT.parse(body);
return done(xrd.toJSON());
});
}
], function (result) {
if (result) {
cb(null, result);
} else {
cb('no-host-meta');
}
});
};