From fda5a5263051f80050d4985480d7a2b6a45f5245 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Thu, 30 Sep 2021 17:35:09 +0100 Subject: [PATCH] Fix app creation when there is no app ctx --- packages/server/src/middleware/usageQuota.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/server/src/middleware/usageQuota.js b/packages/server/src/middleware/usageQuota.js index de54c93200..c62f0078cd 100644 --- a/packages/server/src/middleware/usageQuota.js +++ b/packages/server/src/middleware/usageQuota.js @@ -39,7 +39,6 @@ module.exports = async (ctx, next) => { return next() } - const db = new CouchDB(ctx.appId) let usage = METHOD_MAP[ctx.req.method] const property = getProperty(ctx.req.url) if (usage == null || property == null) { @@ -48,7 +47,10 @@ module.exports = async (ctx, next) => { // post request could be a save of a pre-existing entry if (ctx.request.body && ctx.request.body._id && ctx.request.body._rev) { try { - await db.get(ctx.request.body._id) + if (ctx.appId) { + const db = new CouchDB(ctx.appId) + await db.get(ctx.request.body._id) + } return next() } catch (err) { ctx.throw(404, `${ctx.request.body._id} does not exist`)