From e8a443ada4204309f184348b45fe751d4ae2bcd9 Mon Sep 17 00:00:00 2001 From: Diluka Date: Wed, 3 Apr 2019 16:33:57 +0800 Subject: [PATCH 1/3] fix(route): mount path hand over to external app --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 35157071..646983f6 100644 --- a/index.js +++ b/index.js @@ -12,8 +12,8 @@ function run(config, listenOpts = {}) { app.locals.appBasePath = listenOpts.basePath || app.locals.appBasePath; - app.use(app.locals.appBasePath, express.static(path.join(__dirname, 'public'))); - app.use(app.locals.appBasePath, routes); + app.use('/', express.static(path.join(__dirname, 'public'))); + app.use('/', routes); const port = listenOpts.port || 4567; const host= listenOpts.host || '0.0.0.0'; // Default: listen to all network interfaces. From 1940b1f32c532df22c5c9c573a904c7bbd6770e2 Mon Sep 17 00:00:00 2001 From: Diluka W Date: Wed, 3 Apr 2019 17:18:21 +0800 Subject: [PATCH 2/3] fix(route): hbs basePath --- src/server/views/dashboard/jobDetails.js | 2 +- src/server/views/dashboard/queueDetails.js | 2 +- src/server/views/dashboard/queueJobsByState.js | 2 +- src/server/views/dashboard/queueList.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/server/views/dashboard/jobDetails.js b/src/server/views/dashboard/jobDetails.js index 13935072..03708290 100644 --- a/src/server/views/dashboard/jobDetails.js +++ b/src/server/views/dashboard/jobDetails.js @@ -4,7 +4,7 @@ const util = require('util'); async function handler(req, res) { const { queueName, queueHost, id } = req.params; const { json } = req.query; - const basePath = req.baseUrl; + const basePath = req.app.locals.appBasePath + req.baseUrl; const {Queues} = req.app.locals; const queue = await Queues.get(queueName, queueHost); diff --git a/src/server/views/dashboard/queueDetails.js b/src/server/views/dashboard/queueDetails.js index e9a59e5c..4dfeb6d4 100644 --- a/src/server/views/dashboard/queueDetails.js +++ b/src/server/views/dashboard/queueDetails.js @@ -5,7 +5,7 @@ async function handler(req, res) { const {queueName, queueHost} = req.params; const {Queues} = req.app.locals; const queue = await Queues.get(queueName, queueHost); - const basePath = req.baseUrl; + const basePath = req.app.locals.appBasePath + req.baseUrl; if (!queue) return res.status(404).render('dashboard/templates/queueNotFound', {basePath, queueName, queueHost}); let jobCounts; diff --git a/src/server/views/dashboard/queueJobsByState.js b/src/server/views/dashboard/queueJobsByState.js index 8a76f186..d3ad252d 100644 --- a/src/server/views/dashboard/queueJobsByState.js +++ b/src/server/views/dashboard/queueJobsByState.js @@ -60,7 +60,7 @@ async function _html(req, res) { const { queueName, queueHost, state } = req.params; const {Queues} = req.app.locals; const queue = await Queues.get(queueName, queueHost); - const basePath = req.baseUrl; + const basePath = req.app.locals.appBasePath + req.baseUrl; if (!queue) return res.status(404).render('dashboard/templates/queueNotFound', {basePath, queueName, queueHost}); if (!isValidState(state, queue.IS_BEE)) return res.status(400).json({ message: `Invalid state requested: ${state}` }); diff --git a/src/server/views/dashboard/queueList.js b/src/server/views/dashboard/queueList.js index c9119165..5cfe6c90 100644 --- a/src/server/views/dashboard/queueList.js +++ b/src/server/views/dashboard/queueList.js @@ -1,7 +1,7 @@ function handler(req, res) { const {Queues} = req.app.locals; const queues = Queues.list(); - const basePath = req.baseUrl; + const basePath = req.app.locals.appBasePath + req.baseUrl; return res.render('dashboard/templates/queueList', { basePath, queues }); } From c59f8a03ae3472499f4ea7f5970760016bfd6ca3 Mon Sep 17 00:00:00 2001 From: Diluka W Date: Wed, 3 Apr 2019 17:41:15 +0800 Subject: [PATCH 3/3] fix(route): keep standalone like before --- index.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 646983f6..91fa56cf 100644 --- a/index.js +++ b/index.js @@ -10,10 +10,14 @@ function run(config, listenOpts = {}) { if (config) Queues.setConfig(config); Queues.useCdn = typeof listenOpts.useCdn !== 'undefined' ? listenOpts.useCdn : true; - app.locals.appBasePath = listenOpts.basePath || app.locals.appBasePath; - - app.use('/', express.static(path.join(__dirname, 'public'))); - app.use('/', routes); + if (listenOpts.disableListen) { + app.locals.appBasePath = listenOpts.basePath || app.locals.appBasePath; + app.use('/', express.static(path.join(__dirname, 'public'))); + app.use('/', routes); + } else { + app.use(listenOpts.basePath || app.locals.appBasePath, express.static(path.join(__dirname, 'public'))); + app.use(listenOpts.basePath || app.locals.appBasePath, routes); + } const port = listenOpts.port || 4567; const host= listenOpts.host || '0.0.0.0'; // Default: listen to all network interfaces.