Start using req.resources = { app, volume, ...} pattern
Reason was that req.app was clashing with expressjs v5 which stores the main expressjs app object there
This commit is contained in:
+10
-9
@@ -25,14 +25,15 @@ async function load(req, res, next) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
if (!result) return next(new HttpError(404, 'Task not found'));
|
||||
|
||||
req.task = result;
|
||||
req.resources.task = result;
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
async function get(req, res, next) {
|
||||
assert.strictEqual(typeof req.params.taskId, 'string');
|
||||
|
||||
next(new HttpSuccess(200, tasks.removePrivateFields(req.task)));
|
||||
next(new HttpSuccess(200, tasks.removePrivateFields(req.resources.task)));
|
||||
}
|
||||
|
||||
async function list(req, res, next) {
|
||||
@@ -51,16 +52,16 @@ async function list(req, res, next) {
|
||||
}
|
||||
|
||||
async function stopTask(req, res, next) {
|
||||
assert.strictEqual(typeof req.task, 'object');
|
||||
assert.strictEqual(typeof req.resources.task, 'object');
|
||||
|
||||
const [error] = await safe(tasks.stopTask(req.task.id));
|
||||
const [error] = await safe(tasks.stopTask(req.resources.task.id));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(204, {}));
|
||||
}
|
||||
|
||||
async function getLogs(req, res, next) {
|
||||
assert.strictEqual(typeof req.task, 'object');
|
||||
assert.strictEqual(typeof req.resources.task, 'object');
|
||||
|
||||
const lines = 'lines' in req.query ? parseInt(req.query.lines, 10) : 10; // we ignore last-event-id
|
||||
if (isNaN(lines)) return next(new HttpError(400, 'lines must be a number'));
|
||||
@@ -71,12 +72,12 @@ async function getLogs(req, res, next) {
|
||||
format: req.query.format || 'json'
|
||||
};
|
||||
|
||||
const [error, logStream] = await safe(tasks.getLogs(req.task, options));
|
||||
const [error, logStream] = await safe(tasks.getLogs(req.resources.task, options));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/x-logs',
|
||||
'Content-Disposition': `attachment; filename="task-${req.task.id}.log"`,
|
||||
'Content-Disposition': `attachment; filename="task-${req.resources.task.id}.log"`,
|
||||
'Cache-Control': 'no-cache',
|
||||
'X-Accel-Buffering': 'no' // disable nginx buffering
|
||||
});
|
||||
@@ -86,7 +87,7 @@ async function getLogs(req, res, next) {
|
||||
|
||||
// this route is for streaming logs
|
||||
async function getLogStream(req, res, next) {
|
||||
assert.strictEqual(typeof req.task, 'object');
|
||||
assert.strictEqual(typeof req.resources.task, 'object');
|
||||
|
||||
const lines = 'lines' in req.query ? parseInt(req.query.lines, 10) : 10; // we ignore last-event-id
|
||||
if (isNaN(lines)) return next(new HttpError(400, 'lines must be a valid number'));
|
||||
@@ -101,7 +102,7 @@ async function getLogStream(req, res, next) {
|
||||
format: 'json'
|
||||
};
|
||||
|
||||
const [error, logStream] = await safe(tasks.getLogs(req.task, options));
|
||||
const [error, logStream] = await safe(tasks.getLogs(req.resources.task, options));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
res.writeHead(200, {
|
||||
|
||||
Reference in New Issue
Block a user