Skip to content

Commit 8145069

Browse files
Improve the console messaging on starting the app to avoid confusion. (#292)
* Improve the console messaging on starting the app to avoid confusion. * Revise logging to present intended URI alongside actual --------- Co-authored-by: Danyal Aytekin <danyal@alienpaper.com>
1 parent 13134f6 commit 8145069

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

app.js

-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ function initApp(config, callback) {
3838

3939
const app = new EventEmitter();
4040

41-
app.address = null;
4241
app.express = express();
4342
app.server = http.createServer(app.express);
4443
app.webservice = createClient(webserviceUrl);
@@ -179,8 +178,6 @@ function loadErrorHandling(app, config, callback) {
179178
});
180179

181180
app.server.listen(config.port, error => {
182-
const address = app.server.address();
183-
app.address = `http://${address.address}:${address.port}`;
184181
callback(error, app);
185182
});
186183
}

index.js

+18-10
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,33 @@
1414
// along with Pa11y Dashboard. If not, see <http://www.gnu.org/licenses/>.
1515
'use strict';
1616

17+
const initService = require('pa11y-webservice');
1718
const kleur = require('kleur');
19+
1820
const config = require('./config');
21+
const initDashboard = require('./app');
1922

2023
process.on('SIGINT', () => {
2124
console.log('\nGracefully shutting down from SIGINT (Ctrl-C)');
2225
process.exit();
2326
});
2427

25-
require('./app')(config, (error, app) => {
28+
initDashboard(config, (error, app) => {
2629
if (error) {
2730
console.error(error.stack);
2831
process.exit(1);
2932
}
3033

31-
console.log('');
32-
console.log(kleur.underline().magenta('Pa11y Dashboard started'));
33-
console.log(kleur.grey('mode: %s'), process.env.NODE_ENV);
34-
console.log(kleur.grey('uri: %s'), app.address);
34+
const mode = process.env.NODE_ENV;
35+
const dashboardAddress = app.server.address();
36+
37+
console.log(kleur.underline().magenta('\nPa11y Dashboard started'));
38+
console.log(kleur.grey('mode: %s'), mode);
39+
console.log(kleur.grey('uri (intended): %s'), `http://localhost:${config.port}/`);
40+
console.log(
41+
kleur.grey(`uri (actual, ${dashboardAddress.family}): %s`),
42+
`http://${dashboardAddress.address}:${dashboardAddress.port}/`
43+
);
3544

3645
app.on('route-error', routeError => {
3746
const stack = (routeError.stack ? routeError.stack.split('\n') : [routeError.message]);
@@ -43,19 +52,18 @@ require('./app')(config, (error, app) => {
4352

4453
// Start the webservice if required
4554
if (typeof config.webservice === 'object') {
46-
require('pa11y-webservice')(config.webservice, (webserviceError, webservice) => {
55+
console.log(kleur.underline().cyan('\nPa11y Webservice starting'));
56+
initService(config.webservice, (webserviceError, webservice) => {
4757
if (webserviceError) {
4858
console.error(webserviceError.stack);
4959
process.exit(1);
5060
}
5161

52-
console.log('');
53-
console.log(kleur.underline().cyan('Pa11y Webservice started'));
54-
console.log(kleur.grey('mode: %s'), process.env.NODE_ENV);
62+
console.log(kleur.cyan('\nPa11y Webservice started'));
63+
console.log(kleur.grey('mode: %s'), mode);
5564
console.log(kleur.grey('uri: %s'), webservice.server.info.uri);
5665
console.log(kleur.grey('database: %s'), config.webservice.database);
5766
console.log(kleur.grey('cron: %s'), config.webservice.cron);
5867
});
5968
}
60-
6169
});

0 commit comments

Comments
 (0)