Skip to content

Commit

Permalink
[server] make renderApp async
Browse files Browse the repository at this point in the history
this also makes renderStatusPage async, by extension.
  • Loading branch information
spalger committed Mar 16, 2016
1 parent 7405d18 commit 2671cdb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/server/status/index.js
Expand Up @@ -20,18 +20,18 @@ module.exports = function (kbnServer, server, config) {
}
});

server.decorate('reply', 'renderStatusPage', function () {
server.decorate('reply', 'renderStatusPage', async function () {
var app = kbnServer.uiExports.getHiddenApp('status_page');
var resp = app ? this.renderApp(app) : this(kbnServer.status.toString());
var resp = app ? await this.renderApp(app) : this(kbnServer.status.toString());
resp.code(kbnServer.status.isGreen() ? 200 : 503);
return resp;
});

server.route({
method: 'GET',
path: '/status',
handler: function (request, reply) {
return reply.renderStatusPage();
handler: async function (request, reply) {
return await reply.renderStatusPage();
}
});
};
22 changes: 13 additions & 9 deletions src/ui/index.js
Expand Up @@ -46,33 +46,37 @@ module.exports = async (kbnServer, server, config) => {
server.route({
path: '/app/{id}',
method: 'GET',
handler: function (req, reply) {
handler: async function (req, reply) {
let id = req.params.id;
let app = uiExports.apps.byId[id];
if (!app) return reply(Boom.notFound('Unknown app ' + id));

if (kbnServer.status.isGreen()) {
return reply.renderApp(app);
return await reply.renderApp(app);
} else {
return reply.renderStatusPage();
return await reply.renderStatusPage();
}
}
});

const getDefaultInjectedVars = once(function createDefaultInjectedVars() {
const injectors = uiExports.defaultVariableInjectors;
return defaults({}, ...injectors.map(injector => (injector() || {})));
});
async function getDefaultInjectedVars() {
const vars = Promise.map(uiExports.defaultVariableInjectors, async injector => {
const toInject = await injector();
return toInject || {};
});

return defaults({}, ...vars);
};

server.decorate('reply', 'renderApp', function (app) {
server.decorate('reply', 'renderApp', async function (app) {
const payload = {
app: app,
nav: uiExports.apps,
version: kbnServer.version,
buildNum: config.get('pkg.buildNum'),
buildSha: config.get('pkg.buildSha'),
basePath: config.get('server.basePath'),
vars: defaults(app.getInjectedVars() || {}, getDefaultInjectedVars()),
vars: defaults(app.getInjectedVars() || {}, await getDefaultInjectedVars()),
};

return this.view(app.templateName, {
Expand Down

0 comments on commit 2671cdb

Please sign in to comment.