Fix redirect
This commit is contained in:
parent
5a0cdc2a07
commit
00feecd9ff
2 changed files with 21 additions and 16 deletions
2
app.js
2
app.js
|
|
@ -29,9 +29,11 @@ function getCertCachePath(host) {
|
|||
}
|
||||
async function findMaintainerEmail(host) {
|
||||
const resolve = await axios(`https://dns.google/resolve?name=${encodeURIComponent(host)}&type=TXT`);
|
||||
if (resolve.data.Answer) {
|
||||
for (const head of resolve.data.Answer) {
|
||||
return head.data.slice(record_email_prefix.length);
|
||||
}
|
||||
}
|
||||
throw new Error(record_email_prefix + ' TXT is missing');
|
||||
}
|
||||
|
||||
|
|
|
|||
9
index.js
9
index.js
|
|
@ -15,6 +15,7 @@ const resolveCache = {};
|
|||
|
||||
async function buildCache(host) {
|
||||
const resolve = await axios(`https://dns.google/resolve?name=${encodeURIComponent(host)}&type=TXT`);
|
||||
if (resolve.data.Answer) {
|
||||
for (const head of resolve.data.Answer) {
|
||||
let url = head.data.slice(record_prefix.length);
|
||||
let expand = false;
|
||||
|
|
@ -28,6 +29,7 @@ async function buildCache(host) {
|
|||
expire: Date.now() + Math.max(head.TTL, 86400) * 1000,
|
||||
};
|
||||
}
|
||||
}
|
||||
throw new Error(record_prefix + ' TXT is missing');
|
||||
}
|
||||
|
||||
|
|
@ -38,11 +40,12 @@ const server = http.createServer(async function (req, res) {
|
|||
cache = await buildCache(req.headers.host);
|
||||
resolveCache[req.headers.host] = cache;
|
||||
}
|
||||
req.statusCode = 301;
|
||||
req.headers.location = cache.expand ? cache.url + req.url : cache.url;
|
||||
res.writeHead(301, {
|
||||
'Location': cache.expand ? cache.url + req.url : cache.url,
|
||||
});
|
||||
return;
|
||||
} catch (error) {
|
||||
res.statusCode = 400;
|
||||
res.writeHead(400);
|
||||
res.write(error.message || 'Unknown error');
|
||||
} finally {
|
||||
res.end();
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue