|
|
@ -1,4 +1,5 @@ |
|
|
|
// Packages
|
|
|
|
import PublicSuffixList from 'publicsuffixlist' |
|
|
|
import chalk from 'chalk' |
|
|
|
|
|
|
|
// Ours
|
|
|
@ -9,6 +10,9 @@ import {DOMAIN_VERIFICATION_ERROR} from './errors' |
|
|
|
import Now from './' |
|
|
|
|
|
|
|
const domainRegex = /^((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}$/ |
|
|
|
const psl = new PublicSuffixList() |
|
|
|
|
|
|
|
psl.initializeSync() |
|
|
|
|
|
|
|
export default class Alias extends Now { |
|
|
|
|
|
|
@ -121,16 +125,18 @@ export default class Alias extends Now { |
|
|
|
console.log(`> ${chalk.bold(chalk.underline(alias))} is a custom domain.`) |
|
|
|
console.log(`> Verifying the DNS settings for ${chalk.bold(chalk.underline(alias))} (see ${chalk.underline('https://zeit.world')} for help)`) |
|
|
|
|
|
|
|
const {domain, nameservers} = await this.getNameservers(alias) |
|
|
|
const _domain = psl.domain(alias) |
|
|
|
const _domainInfo = await this.getDomain(_domain) |
|
|
|
const domainInfo = _domainInfo && !_domainInfo.error ? _domainInfo : undefined |
|
|
|
const {domain, nameservers} = domainInfo ? {domain: _domain} : await this.getNameservers(alias) |
|
|
|
const usingZeitWorld = domainInfo ? !domainInfo.isExternal : isZeitWorld(nameservers) |
|
|
|
let skipDNSVerification = false |
|
|
|
|
|
|
|
if (this._debug) { |
|
|
|
console.log(`> [debug] Found domain ${domain} and nameservers ${nameservers}`) |
|
|
|
} |
|
|
|
|
|
|
|
if (!isZeitWorld(nameservers)) { |
|
|
|
const domainInfo = await this.getDomain(domain) |
|
|
|
|
|
|
|
if (!usingZeitWorld && domainInfo) { |
|
|
|
if (domainInfo.verified) { |
|
|
|
skipDNSVerification = true |
|
|
|
} else if (domainInfo.uid) { |
|
|
@ -150,7 +156,7 @@ export default class Alias extends Now { |
|
|
|
// in which case we attempt to correct the dns
|
|
|
|
// configuration (if we can!)
|
|
|
|
try { |
|
|
|
if (isZeitWorld(nameservers)) { |
|
|
|
if (usingZeitWorld) { |
|
|
|
console.log(`> Detected ${chalk.bold(chalk.underline('zeit.world'))} nameservers! Configuring records.`) |
|
|
|
const record = alias.substr(0, alias.length - domain.length) |
|
|
|
|
|
|
@ -196,12 +202,19 @@ export default class Alias extends Now { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!isZeitWorld(nameservers) && !skipDNSVerification) { |
|
|
|
if (!usingZeitWorld && !skipDNSVerification) { |
|
|
|
if (this._debug) { |
|
|
|
console.log(`> [debug] Trying to register a non-ZeitWorld domain ${domain} for the current user`) |
|
|
|
} |
|
|
|
|
|
|
|
await this.setupDomain(domain, {isExternal: true}) |
|
|
|
const {uid, verified, verifyToken, created} = await this.setupDomain(domain, {isExternal: true}) |
|
|
|
if (created && verified) { |
|
|
|
console.log(`${chalk.cyan('> Success!')} Domain ${chalk.bold(chalk.underline(domain))} ${chalk.dim(`(${uid})`)} added`) |
|
|
|
} else if (verifyToken) { |
|
|
|
const e = new Error(`> Verification required: Please add the following TXT record on the external DNS server: _now.${domain}: ${verifyToken}`) |
|
|
|
e.userError = true |
|
|
|
throw e |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
console.log(`> Verification ${chalk.bold('OK')}!`) |
|
|
|