From 8f636173a03c5c99af61889b963ed15fedcfb1dd Mon Sep 17 00:00:00 2001 From: Rowan Manning Date: Thu, 21 Nov 2013 09:12:54 +0000 Subject: [PATCH] Allow the webservice to run automatically --- app.js | 7 ++++++- config/development.sample.json | 9 ++++++++- config/production.sample.json | 10 ++++++++-- index.js | 10 ++++++++++ package.json | 1 + 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index 3fafba4..969c4b0 100644 --- a/app.js +++ b/app.js @@ -13,11 +13,16 @@ module.exports = initApp; function initApp (config, callback) { config = defaultConfig(config); + var webserviceUrl = config.webservice; + if (typeof webserviceUrl == 'object') { + webserviceUrl = 'http://' + webserviceUrl.host + ':' + webserviceUrl.port + '/'; + } + var app = new EventEmitter(); app.address = null; app.express = express(); app.server = http.createServer(app.express); - app.webservice = createClient(config.webservice); + app.webservice = createClient(webserviceUrl); // Compression app.express.use(express.compress()); diff --git a/config/development.sample.json b/config/development.sample.json index 711b028..1a11916 100644 --- a/config/development.sample.json +++ b/config/development.sample.json @@ -2,5 +2,12 @@ "webservice": "http://localhost:3000/", "port": 4000, "noindex": true, - "readonly": false + "readonly": false, + + "webservice": { + "database": "mongodb://localhost/pa11y-webservice-dev", + "host": "0.0.0.0", + "port": 3000, + "cron": "0 30 0 * * *" + } } \ No newline at end of file diff --git a/config/production.sample.json b/config/production.sample.json index 711b028..6057169 100644 --- a/config/production.sample.json +++ b/config/production.sample.json @@ -1,6 +1,12 @@ { - "webservice": "http://localhost:3000/", "port": 4000, "noindex": true, - "readonly": false + "readonly": false, + + "webservice": { + "database": "mongodb://localhost/pa11y-webservice", + "host": "0.0.0.0", + "port": 3000, + "cron": "0 30 0 * * *" + } } \ No newline at end of file diff --git a/index.js b/index.js index 8a48f2d..b2f48d2 100644 --- a/index.js +++ b/index.js @@ -18,4 +18,14 @@ require('./app')(config, function (err, app) { console.error(chalk.grey(stack.join('\n'))); }); + // Start the webservice if required + if (typeof config.webservice === 'object') { + require('pa11y-webservice')(config.webservice, function (err, webservice) { + console.log(''); + console.log(chalk.underline.cyan('pa11y-webservice started')); + console.log(chalk.grey('mode: %s'), process.env.NODE_ENV); + console.log(chalk.grey('uri: %s'), webservice.server.info.uri); + }); + } + }); diff --git a/package.json b/package.json index 0a3349b..126db1c 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "express": "~3.4", "express-hbs": "~0.2", "moment": "~2.2", + "pa11y-webservice": "~1.1", "pa11y-webservice-client-node": "~1.0", "underscore": "~1.5" },