[BREAKING CHANGE] add _. for TXT

Just realized I can't put TXT on CNAME :/
This commit is contained in:
Wildan M 2021-09-21 06:12:17 +07:00
commit 6b2a6e8186
4 changed files with 23 additions and 11 deletions

View file

@ -27,8 +27,8 @@ To forward from `www.old.com` to `old.com`, add these records to your DNS:
```
www.old.com IN CNAME r.forwarddomain.net
www.old.com IN TXT forward-domain=https://old.com/*
www.old.com IN TXT forward-domain-cert-maintainer=<your email address>
_.www.old.com IN TXT forward-domain=https://old.com/*
_.www.old.com IN TXT forward-domain-cert-maintainer=<your email address>
```
> IMPORTANT: replace `<your email address>` with your email address!
@ -37,13 +37,12 @@ Because CNAME can't be used in apex domains, you can use A/AAAA records.<br>
To forward from `old.com` to `new.net`, add these records to your DNS:
```
old.com IN A 206.189.61.89
old.com IN AAAA 2a03:b0c0:3:d0::13a8:c001
old.com IN TXT forward-domain=https://new.net/*
old.com IN TXT forward-domain-cert-maintainer=<your email address>
old.com IN A 167.172.5.31
_.old.com IN TXT forward-domain=https://new.net/*
_.old.com IN TXT forward-domain-cert-maintainer=<your email address>
```
> BETA service notice: IP addresses can change anytime (with notice).
> BETA service notice: IP addresses may change anytime.
## FAQ

View file

@ -35,12 +35,12 @@ const acme_prefix = '/.well-known/acme-challenge/';
const listener = async function (/** @type {import('http').IncomingMessage} */ req, /** @type {import('http').ServerResponse} */ res) {
try {
if (req.url.startsWith(acme_prefix)) {
if (client.challengeCallbacks) {
if (client.challengeCallbacks[req.headers.host]) {
res.writeHead(200, {
// This is important :)
'content-type': 'application/octet-stream'
});
res.write(client.challengeCallbacks());
res.write(client.challengeCallbacks[req.headers.host]());
} else {
res.writeHead(404)
}

View file

@ -22,10 +22,16 @@ function getCertCachePath(host) {
return path.join(certsDir, hash.substr(0, 2), hash.substr(2), host);
}
/**
* @param {string} host
*/
async function findMaintainerEmail(host) {
return await findTxtRecord(host, record_email_prefix);
}
/**
* @param {string} host
*/
async function buildCache(host) {
const dir = getCertCachePath(host);
const keyP = path.join(dir, 'privateKey.pem');
@ -64,6 +70,9 @@ async function buildCache(host) {
}
/**
* @param {string} servername
*/
async function getKeyCert(servername) {
let cache = resolveCache[servername];
await ensureDir(certsDir);

View file

@ -17,8 +17,12 @@ async function ensureDir(dir) {
}
}
/**
* @param {string} host
* @param {string} prefix
*/
async function findTxtRecord(host, prefix, required = true) {
const resolve = await axios(`https://dns.google/resolve?name=${encodeURIComponent(host)}&type=TXT`);
const resolve = await axios(`https://dns.google/resolve?name=_.${encodeURIComponent(host)}&type=TXT`);
if (resolve.data.Answer) {
for (const head of resolve.data.Answer) {
if (!head.data.startsWith(prefix))