Philip H
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
36 additions and
2 deletions
-
src/lib/Server.js
-
src/lib/Util.js
|
|
|
@ -70,8 +70,7 @@ module.exports = class Server { |
|
|
|
} |
|
|
|
|
|
|
|
ctx.session.authenticated = true; |
|
|
|
|
|
|
|
ctx.status = 204; |
|
|
|
ctx.session.save(); |
|
|
|
|
|
|
|
debug(`New Session: ${ctx.session.id}`); |
|
|
|
}) |
|
|
|
|
|
|
|
@ -17,6 +17,41 @@ module.exports = class Util { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
static promisify(fn) { |
|
|
|
// eslint-disable-next-line func-names
|
|
|
|
return function(req, res) { |
|
|
|
Promise.resolve().then(async () => fn(req, res)) |
|
|
|
.then((result) => { |
|
|
|
if (res.headersSent) return; |
|
|
|
|
|
|
|
if (typeof result === 'undefined') { |
|
|
|
return res |
|
|
|
.status(204) |
|
|
|
.end(); |
|
|
|
} |
|
|
|
|
|
|
|
return res |
|
|
|
.status(200) |
|
|
|
.json(result); |
|
|
|
}) |
|
|
|
.catch((error) => { |
|
|
|
if (typeof error === 'string') { |
|
|
|
error = new Error(error); |
|
|
|
} |
|
|
|
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.error(error); |
|
|
|
|
|
|
|
return res |
|
|
|
.status(error.statusCode || 500) |
|
|
|
.json({ |
|
|
|
error: error.message || error.toString(), |
|
|
|
stack: error.stack, |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
static async exec(cmd, { |
|
|
|
log = true, |
|
|
|
} = {}) { |
|
|
|
|