diff --git a/src/server/app.js b/src/server/app.js index 2f3d069131414..9f85fe0afba5c 100644 --- a/src/server/app.js +++ b/src/server/app.js @@ -2,6 +2,7 @@ var express = require('express'); var path = require('path'); var favicon = require('serve-favicon'); var requestLogger = require('./lib/requestLogger'); +var appHeaders = require('./lib/appHeaders'); var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); var compression = require('compression'); @@ -15,9 +16,11 @@ var app = express(); // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); +app.set('x-powered-by', false); app.use(favicon(path.join(config.public_folder, 'styles', 'theme', 'elk.ico'))); app.use(requestLogger()); +app.use(appHeaders()); if (app.get('env') === 'development') { require('./dev')(app); diff --git a/src/server/lib/appHeaders.js b/src/server/lib/appHeaders.js new file mode 100644 index 0000000000000..4cebe2201083e --- /dev/null +++ b/src/server/lib/appHeaders.js @@ -0,0 +1,11 @@ +var path = require('path'); +var pkgPath = path.resolve(__dirname, '..', '..', '..', 'package.json'); +var pkg = require(pkgPath); + +module.exports = function () { + return function (req, res, next) { + res.header('X-App-Name', 'kibana'); + res.header('X-App-Version', pkg.version); + next(); + }; +}; diff --git a/tasks/kibana_server.js b/tasks/kibana_server.js index 11c40c6e8e71c..b0cbab896442e 100644 --- a/tasks/kibana_server.js +++ b/tasks/kibana_server.js @@ -4,7 +4,9 @@ module.exports = function (grunt) { var config = require('../src/server/config'); config.quiet = true; var server = require('../src/server'); + server.start(function () { + grunt.log.ok('Server started on port', config.kibana.port); if (keepalive !== 'keepalive') done(); }); }); diff --git a/tasks/maybe_connect_dev.js b/tasks/maybe_start_kibana.js similarity index 55% rename from tasks/maybe_connect_dev.js rename to tasks/maybe_start_kibana.js index 8e44084a73217..187875e5995a2 100644 --- a/tasks/maybe_connect_dev.js +++ b/tasks/maybe_start_kibana.js @@ -1,25 +1,38 @@ module.exports = function (grunt) { + var config = require('../src/server/config'); + var maybeStartServer = function (options) { return function () { var http = require('http'); - - var req = http.request({ + var opts = { method: 'HEAD', path: '/', host: 'localhost', port: options.port - }); + }; + + grunt.log.debug('checking for server', JSON.stringify(opts)); + + var req = http.request(opts); function onResponse(res) { - if (res.statusCode === 200) { - grunt.log.writeln('server already started'); + grunt.log.debug('Server responded with', res.statusCode); + var app = res.headers['x-app-name']; + + if (res.statusCode === 200 && app && app === 'kibana') { + grunt.log.ok('Kibana server already started on port', options.port); } else { - grunt.log.error('another server is already running at localhost:8000!'); + grunt.log.error('Another server is already running on port', options.port); + process.exit(1); } done(res); } - function onError() { + function onError(err) { + if (err.code !== 'ECONNREFUSED') { + grunt.log.error('Kibana server check failed', err); + } + grunt.config.set(options.name, true); grunt.task.run(options.tasks); done(); @@ -39,9 +52,10 @@ module.exports = function (grunt) { req.end(); }; }; + grunt.registerTask('maybe_start_kibana', maybeStartServer({ name: 'kibana-server', - port: 5601, + port: config.kibana.port, tasks: ['kibana_server'] })); };