Skip to content

Commit 049f351

Browse files
committed
feat(nginx): check dns entry exists before attempting ssl setup
refs #190 - adds check to ssl setup that ensures DNS entry exists before trying to get an SSL certificate
1 parent ec1f690 commit 049f351

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

extensions/nginx/index.js

+22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const fs = require('fs-extra');
4+
const dns = require('dns');
45
const url = require('url');
56
const path = require('path');
67
const execa = require('execa');
@@ -107,6 +108,27 @@ class NginxExtension extends cli.Extension {
107108
let rootPath = path.resolve(ctx.instance.dir, 'system', 'nginx-root');
108109

109110
return this.ui.listr([{
111+
title: 'Checking DNS resolution',
112+
task: () => {
113+
return Promise.fromNode(cb => dns.lookup(parsedUrl.hostname, {family: 4}, cb)).catch((error) => {
114+
if (error.code !== 'ENOTFOUND') {
115+
// Some other error
116+
return Promise.reject(error);
117+
}
118+
119+
// DNS entry has not populated yet, log an error and skip rest of the
120+
// ssl configuration
121+
let text = [
122+
'Uh-oh! It looks like your domain isn\'t set up correctly yet.',
123+
'Because of this, SSL setup won\'t work correctly. Once you\'ve set up your domain',
124+
'and pointed it at this server\'s IP, try running `ghost setup ssl` again.'
125+
];
126+
127+
this.ui.log(text.join(' '), 'yellow');
128+
return task.skip();
129+
});
130+
}
131+
}, {
110132
title: 'Preparing nginx for SSL configuration',
111133
task: (ctx) => {
112134
return argv.sslemail ? Promise.resolve({email: argv.sslemail}) : this.ui.prompt({

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -1321,7 +1321,7 @@ glob-parent@^2.0.0:
13211321
dependencies:
13221322
is-glob "^2.0.0"
13231323

1324-
[email protected], glob@^7.0.5:
1324+
13251325
version "7.1.1"
13261326
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8"
13271327
dependencies:
@@ -1352,7 +1352,7 @@ glob@^6.0.1:
13521352
once "^1.3.0"
13531353
path-is-absolute "^1.0.0"
13541354

1355-
glob@^7.0.3, glob@^7.1.2:
1355+
glob@^7.0.3, glob@^7.0.5, glob@^7.1.2:
13561356
version "7.1.2"
13571357
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"
13581358
dependencies:
@@ -1883,14 +1883,14 @@ js-tokens@^3.0.0:
18831883
version "3.0.1"
18841884
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.1.tgz#08e9f132484a2c45a30907e9dc4d5567b7f114d7"
18851885

1886-
1886+
18871887
version "3.6.1"
18881888
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.6.1.tgz#6e5fe67d8b205ce4d22fad05b7781e8dadcc4b30"
18891889
dependencies:
18901890
argparse "^1.0.7"
18911891
esprima "^2.6.0"
18921892

1893-
js-yaml@^3.8.4:
1893+
js-yaml@3.x, js-yaml@^3.8.4:
18941894
version "3.8.4"
18951895
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.8.4.tgz#520b4564f86573ba96662af85a8cafa7b4b5a6f6"
18961896
dependencies:

0 commit comments

Comments
 (0)