Browse Source

alias: verify ownership first for custom domains

master
Guillermo Rauch 9 years ago
parent
commit
1b5c88eedb
  1. 17
      lib/alias.js

17
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', {

Loading…
Cancel
Save