Browse Source

Merge pull request #122 from zeit/domain-api-rework

Always register the domain for the user before trying to use it
master
Tony Kovanen 8 years ago
committed by GitHub
parent
commit
c4c9786821
  1. 10
      lib/alias.js
  2. 4
      lib/index.js

10
lib/alias.js

@ -105,6 +105,9 @@ 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);
if (this._debug) console.log(`> [debug] Found domain ${domain} and nameservers ${nameservers}`);
try {
await this.verifyOwnership(alias);
} catch (err) {
@ -113,8 +116,6 @@ export default class Alias extends Now {
// in which case we attempt to correct the dns
// configuration (if we can!)
try {
const { domain, nameservers } = await this.getNameservers(alias);
if (this._debug) console.log(`> [debug] Found domain ${domain} and nameservers ${nameservers}`);
if (isZeitWorld(nameservers)) {
console.log(`> Detected ${chalk.bold(chalk.underline('zeit.world'))} nameservers! Configuring records.`);
const record = alias.substr(0, alias.length - domain.length);
@ -158,6 +159,11 @@ export default class Alias extends Now {
}
}
if (!isZeitWorld(nameservers)) {
if (this._debug) console.log(`> [debug] Trying to register a non-ZeitWorld domain ${domain} for the current user`);
this.setupDomain(domain, { isExternal: true });
}
console.log(`> Verification ${chalk.bold('OK')}!`);
}

4
lib/index.js

@ -372,12 +372,12 @@ export default class Now extends EventEmitter {
}
// _ensures_ the domain is setup (idempotent)
setupDomain (name) {
setupDomain (name, { isExternal } = {}) {
return this.retry(async (bail, attempt) => {
if (this._debug) console.time(`> [debug] #${attempt} POST /domains`);
const res = await this._fetch('/domains', {
method: 'POST',
body: { name }
body: { name, isExternal: !!isExternal }
});
if (this._debug) console.timeEnd(`> [debug] #${attempt} POST /domains`);

Loading…
Cancel
Save