fix(script): adds explicit A record for URL redirection. Fixes #2365

This commit is contained in:
Akshay Nair
2022-05-15 21:22:10 +05:30
parent 1279a94e9e
commit 99e45067b5
3 changed files with 30 additions and 17 deletions

1
.env
View File

@@ -3,3 +3,4 @@ DOMAIN_API_KEY=apikey
DOMAIN_API_HOST=api-example.com
DOMAIN_API_PORT=2087
DOMAIN_DOMAIN=example.com
DOMAIN_HOST_IP=69.69.69.69

View File

@@ -1,29 +1,39 @@
const R = require('ramda');
const { VALID_RECORD_TYPES, TTL, ENV } = require('../utils/constants');
const { VALID_RECORD_TYPES, DOMAIN_HOST_IP, TTL, ENV } = require('../utils/constants');
const { domainService: dc } = require('../utils/domain-service');
const { getDomains: gd } = require('../utils/get-domain');
// Allow TXT records while publishing (for pcl validation)
const getRecords = R.compose(R.toPairs, R.pick(VALID_RECORD_TYPES));
const address = (type, url) => {
if ('URL' === type) return `${url}`.replace(/\/$/g, '');
if ('TXT' === type) return url;
return (type === 'CNAME' ? `${url}`.toLowerCase() : `${url}`).replace(/[/.]$/g, '');
const address = (type, value) => {
if ('URL' === type) return `${value}`.replace(/\/$/g, '');
if ('TXT' === type) return value;
return (type === 'CNAME' ? `${value}`.toLowerCase() : `${value}`).replace(/[/.]$/g, '');
};
const toHostList = R.chain(data => {
const rs = getRecords(data.record);
// URL redirection must contain explicit A record
// Wildcard A record breaks when used with MX
// Ref: https://github.com/is-a-dev/register/issues/2365
if (data.record.URL) {
data.record.A = [ DOMAIN_HOST_IP ]
}
return R.chain(([recordType, urls]) =>
(Array.isArray(urls) ? urls : [urls]).map((url, index) => ({
name: data.name,
type: recordType,
address: address(recordType, url),
ttl: TTL,
...(recordType === 'MX' ? { priority: index + 20 } : {})
}))
, rs);
return R.pipe(
data.record,
getRecords,
R.chain(([recordType, values]) => {
const valueList = Array.isArray(values) ? values : [values];
return valueList.map((value, index) => ({
name: data.name,
type: recordType,
address: address(recordType, value),
ttl: TTL,
...(recordType === 'MX' ? { priority: index + 20 } : {})
}))
}),
);
});
const registerDomains = async ({ domainService, getDomains, log = () => { } }) => {

View File

@@ -12,11 +12,12 @@ const {
DOMAIN_DOMAIN,
DOMAIN_API_HOST,
DOMAIN_API_PORT,
DOMAIN_HOST_IP,
} = process.env;
const IS_TEST = ENV === 'test';
const DOMAINS_PATH = require('path').resolve('domains');
const DOMAINS_PATH = path.resolve('domains');
module.exports = {
ENV,
@@ -27,6 +28,7 @@ module.exports = {
DOMAIN_API_KEY: IS_TEST ? 'testkey' : DOMAIN_API_KEY,
DOMAIN_API_HOST: IS_TEST ? 'example.com' : DOMAIN_API_HOST,
DOMAIN_API_PORT: IS_TEST ? 6969 : DOMAIN_API_PORT,
DOMAIN_HOST_IP,
DOMAINS_PATH,
TTL: 5 * 60 * 60,
};