acme.js-ARCHIVED/lib/browser.js

55 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-10-21 19:45:47 +00:00
'use strict';
var native = module.exports;
native._canCheck = function(me) {
2019-10-21 19:53:50 +00:00
me._canCheck = {};
2019-10-21 19:45:47 +00:00
return me
.request({ url: me._baseUrl + '/api/_acme_api_/' })
.then(function(resp) {
if (resp.body.success) {
me._canCheck['http-01'] = true;
me._canCheck['dns-01'] = true;
}
})
.catch(function() {
// ignore
});
};
native._dns01 = function(me, ch) {
2019-10-25 10:54:40 +00:00
return me
.request({
url: me._baseUrl + '/api/dns/' + ch.dnsHost + '?type=TXT'
})
.then(function(resp) {
var err;
if (!resp.body || !Array.isArray(resp.body.answer)) {
err = new Error('failed to get DNS response');
console.error(err);
throw err;
}
if (!resp.body.answer.length) {
err = new Error('failed to get DNS answer record in response');
console.error(err);
throw err;
}
return {
answer: resp.body.answer.map(function(ans) {
return { data: ans.data, ttl: ans.ttl };
})
};
});
2019-10-21 19:45:47 +00:00
};
native._http01 = function(me, ch) {
var url = encodeURIComponent(ch.challengeUrl);
2019-10-25 10:54:40 +00:00
return me
.request({
url: me._baseUrl + '/api/http?url=' + url
})
.then(function(resp) {
return resp.body;
});
2019-10-21 19:45:47 +00:00
};