Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read kibana's config.js instead of hardcoding in app.js #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ require('./lib/cas-auth.js').configureCas(express, app, config);
require('./lib/es-proxy').configureESProxy(app, config.es_host, config.es_port,
config.es_username, config.es_password);

// Load kibana's config.js
var kibana_config = require('./lib/kibana-config');
kibana_config.elasticsearch = '/__es';

// Serve config.js for kibana3
// We should use special config.js for the frontend and point the ES to __es/
app.get('/config.js', kibana3configjs);
Expand All @@ -54,7 +58,7 @@ function run() {
}

function kibana3configjs(req, res) {


function getKibanaIndex() {
var raw_index = config.kibana_es_index;
Expand All @@ -76,10 +80,8 @@ function kibana3configjs(req, res) {
}
}

kibana_config.kibana_index = getKibanaIndex();

res.setHeader('Content-Type', 'application/javascript');
res.end("define(['settings'], " +
"function (Settings) {'use strict'; return new Settings({elasticsearch: '/__es', default_route : '/dashboard/file/default.json'," +
"kibana_index: '" +
getKibanaIndex() +
"', panel_names: ['histogram', 'map', 'pie', 'table', 'filtering', 'timepicker', 'text', 'hits', 'column', 'trends', 'bettermap', 'query', 'terms', 'sparklines'] }); });");
res.end("define(['settings'], function (Settings) {'use strict'; return new Settings(" + JSON.stringify(kibana_config) + "); });");
}
16 changes: 16 additions & 0 deletions lib/kibana-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// remove comment from javascript source
function removeComment(source) {
return source.replace(/\/\*(.|\n)*?\*\//g, "").replace(/^\s*\/\/.*$/m, "");
}

var fs = require("fs");
var config_source = fs.readFileSync(__dirname + "/../kibana/src/config.js", "utf-8");

// wrap with anonymous function and override 'define', 'window' in it
var config = new Function(
"function define(a, b) { return b(Object); };" +
"var window = {location: {hostname: 'hostname'}};" +
"return " + removeComment(config_source).trim()
)();

module.exports = config;