Last active
August 16, 2018 17:29
-
-
Save KeKs0r/762a2525f2e5cf327e240f0b7827605c to your computer and use it in GitHub Desktop.
Get Bull Admin UI (Arena) working with Hapi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Arena = require('bull-arena'); | |
const _ = require('lodash') | |
function queueToConfig(queue){ | |
return { | |
hostId: 'Main Host', | |
name: queue.name, | |
prefix: queue.keyPrefix, | |
host: queue.eclient.options.host, | |
port: queue.eclient.options.port, | |
password: queue.eclient.options.password, | |
} | |
} | |
module.exports = function HapiArena(server, options, next) { | |
const port = Math.floor(Math.random() * 1000) + 16000; | |
const basePath = '/admin/arena' | |
server.ext('onPostStart', (server, cb) => { | |
const { queues } = server.plugins.bullish | |
const arenaApp = Arena({ | |
queues: _.map(queues,queueToConfig) | |
}, { | |
basePath, | |
port | |
}); | |
server.ext('onPreStop', function (server, next) { | |
arenaApp.close(next) | |
}); | |
cb() | |
}) | |
server.ext('onPostStart', (server, next) => { | |
server.route({ | |
path: basePath + '/{path*}', | |
method: ['GET', 'POST', 'DELETE'], | |
config: { | |
auth: 'admin' | |
}, | |
handler: { | |
proxy: { | |
passThrough: true, | |
mapUri: function (request, callback) { | |
var baseUri = 'http://0.0.0.0:' + port; | |
var destinationUri = baseUri + request.path; | |
server.log(['admin', 'info'], 'Proxying to: ' + destinationUri); | |
callback(null, destinationUri); | |
} | |
} | |
} | |
}); | |
next() | |
}, { after: ['admin']}) | |
next(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment