Browse Source

Improve client side domain verification (#161)

No need to check nameservers if the domain is already known and
verified by now.
master
Olli Vanhoja 8 years ago
committed by Leo Lamprecht
parent
commit
2fdfbbdc22
  1. 27
      lib/alias.js
  2. 1
      package.json

27
lib/alias.js

@ -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')}!`)

1
package.json

@ -88,6 +88,7 @@
"node-fetch": "1.6.3",
"node-version": "1.0.0",
"progress": "1.1.8",
"publicsuffixlist": "0.2.71",
"resumer": "0.0.0",
"semver-compare": "1.0.0",
"socket.io-client": "1.7.1",

Loading…
Cancel
Save