From 1b5c88eedb8070e3476699238595527eb8f80c08 Mon Sep 17 00:00:00 2001 From: Guillermo Rauch Date: Mon, 30 May 2016 09:06:36 -0700 Subject: [PATCH] alias: verify ownership first for custom domains --- lib/alias.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/alias.js b/lib/alias.js index 06881c9..3b953b1 100644 --- a/lib/alias.js +++ b/lib/alias.js @@ -115,6 +115,8 @@ export default class Alias extends Now { } async set (deployment, alias) { + alias = alias.toLowerCase(); + const depl = await this.findDeployment(deployment); if (!depl) { const err = new Error(`Deployment not found by "${deployment}". Run ${chalk.dim('`now ls`')} to see your deployments.`); @@ -130,11 +132,17 @@ export default class Alias extends Now { alias = toHost(alias); } + if (!/\.now\.sh$/.test(alias)) { + console.log(`> ${chalk.bold(chalk.underline(alias))} is a custom domain.`); + console.log(`> Verifying that ${chalk.bold(chalk.underline(alias))} has a ${chalk.dim('`CNAME`')} or ${chalk.dim('`ALIAS`')} record pointing to ${chalk.bold(chalk.underline('alias.zeit.co'))}.`); + await this.verifyOwnership(alias); + } + await this.createAlias(depl, alias); console.log(`${chalk.cyan('> Success!')} Deployment ${chalk.bold(`https://${depl.url}`)} ${chalk.dim(`(${depl.uid})`)} now points to ${chalk.bold(chalk.underline(`https://${alias}`))}`); } - async createAlias (depl, alias) { + createAlias (depl, alias) { return this.retry(async (bail, attempt) => { if (this._debug) console.time(`> [debug] /now/deployments/${depl.uid}/aliases #${attempt}`); const res = await this._fetch(`/now/deployments/${depl.uid}/aliases`, { @@ -177,7 +185,6 @@ export default class Alias extends Now { if ('cert_missing' === code) { console.log(`> Provisioning certificate for ${chalk.underline(chalk.cyan(alias))}`); - await this.verifyOwnership(); await this.createCert(); // try again, but now having provisioned the certificate @@ -194,7 +201,7 @@ export default class Alias extends Now { }); } - async verifyOwnership (domain) { + verifyOwnership (domain) { return this.retry(async (bail, attempt) => { const targets = await resolve4('alias.zeit.co'); @@ -211,7 +218,7 @@ export default class Alias extends Now { for (const ip of ips) { if (!~targets.indexOf(ip)) { - const err = new Error(`The domain ${domain} has an A record ${chalk.bold(ip)} that doesn\'t resolve to ${chalk.bold('alias.zeit.co')}. Make sure the appropriate \`ALIAS\` or \`CNAME\` records are configured.`); + const err = new Error(`The domain ${domain} has an A record ${chalk.bold(ip)} that doesn\'t resolve to ${chalk.bold(chalk.underline('alias.zeit.co'))}. Please check your DNS settings.`); err.userError = true; return bail(err); } @@ -219,7 +226,7 @@ export default class Alias extends Now { }); } - async createCert (domain) { + createCert (domain) { return this.retry(async (bail, attempt) => { if (this._debug) console.time(`> [debug] /certs #${attempt}`); const res = await this._fetch('/certs', {