acme.js/lib/browser.js

55 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2019-10-21 19:45:47 +00:00
'use strict';
var native = module.exports;
2020-07-28 21:53:50 +00:00
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_/' })
2020-07-28 21:53:50 +00:00
.then(function (resp) {
2019-10-21 19:45:47 +00:00
if (resp.body.success) {
me._canCheck['http-01'] = true;
me._canCheck['dns-01'] = true;
}
})
2020-07-28 21:53:50 +00:00
.catch(function () {
2019-10-21 19:45:47 +00:00
// ignore
});
};
2020-07-28 21:53:50 +00:00
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'
})
2020-07-28 21:53:50 +00:00
.then(function (resp) {
2019-10-25 10:54:40 +00:00
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 {
2020-07-28 21:53:50 +00:00
answer: resp.body.answer.map(function (ans) {
2019-10-25 10:54:40 +00:00
return { data: ans.data, ttl: ans.ttl };
})
};
});
2019-10-21 19:45:47 +00:00
};
2020-07-28 21:53:50 +00:00
native._http01 = function (me, ch) {
2019-10-21 19:45:47 +00:00
var url = encodeURIComponent(ch.challengeUrl);
2019-10-25 10:54:40 +00:00
return me
.request({
url: me._baseUrl + '/api/http?url=' + url
})
2020-07-28 21:53:50 +00:00
.then(function (resp) {
2019-10-25 10:54:40 +00:00
return resp.body;
});
2019-10-21 19:45:47 +00:00
};