mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-10-13 10:15:47 +00:00
Merge pull request #2369 from is-a-dev/fix/2365-explicit-a-record-for-url
fix: adds explicit A record for URL redirection + MX
This commit is contained in:
4 files changed
+25
-14
No files matched your search
@@ -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
|
||||
+19
-11
@@ -1,29 +1,37 @@
|
||||
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.MX) {
|
||||
data.record.A = [ DOMAIN_HOST_IP ]
|
||||
}
|
||||
|
||||
return R.chain(([recordType, urls]) =>
|
||||
(Array.isArray(urls) ? urls : [urls]).map((url, index) => ({
|
||||
const records = getRecords(data.record);
|
||||
|
||||
return R.chain(([recordType, values]) => {
|
||||
const valueList = Array.isArray(values) ? values : [values];
|
||||
|
||||
return valueList.map((value, index) => ({
|
||||
name: data.name,
|
||||
type: recordType,
|
||||
address: address(recordType, url),
|
||||
address: address(recordType, value),
|
||||
ttl: TTL,
|
||||
...(recordType === 'MX' ? { priority: index + 20 } : {})
|
||||
}))
|
||||
, rs);
|
||||
}, records)
|
||||
});
|
||||
|
||||
const registerDomains = async ({ domainService, getDomains, log = () => { } }) => {
|
||||
|
||||
+3
-1
@@ -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,
|
||||
};
|
||||
@@ -95,7 +95,7 @@ const getDomainService = ({ cpanel }) => {
|
||||
cpanel.zone.add
|
||||
),
|
||||
recordToZone,
|
||||
print(({ name }) => `Adding zone for ${name}...`),
|
||||
print(r => `Adding zone for ${r.name}: (${r.type} ${r.address})...`),
|
||||
));
|
||||
const removeZoneRecord = lazyTask(R.compose(
|
||||
R.ifElse(R.propEq('type', 'MX'),
|
||||
@@ -103,7 +103,7 @@ const getDomainService = ({ cpanel }) => {
|
||||
R.compose(cpanel.zone.remove, R.pick(['line']))
|
||||
),
|
||||
recordToZone,
|
||||
print(({ name }) => `Deleting zone for ${name}...`),
|
||||
print(r => `Deleting zone for ${r.name}: (${r.type} ${r.address})...`),
|
||||
));
|
||||
const addRedirection = lazyTask(R.compose(
|
||||
cpanel.redirection.add,
|
||||
|
||||
Reference in new issue
Block a user