From 1e318ea26794d5f7617dc2f9239dc2e1180774a8 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 14 Oct 2021 16:16:20 +0100 Subject: [PATCH] Fixing some issues which were causing errors during the cypress test runs, such as not redirect /api/system/ requests to the worker. --- packages/server/src/api/controllers/dev.js | 24 ++++++++++++------- packages/server/src/api/routes/dev.js | 13 ++++++---- .../src/utilities/rowProcessor/index.js | 4 ++++ 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/packages/server/src/api/controllers/dev.js b/packages/server/src/api/controllers/dev.js index d75c4032d7..c43de7f553 100644 --- a/packages/server/src/api/controllers/dev.js +++ b/packages/server/src/api/controllers/dev.js @@ -7,11 +7,13 @@ const { clearLock } = require("../../utilities/redis") const { Replication } = require("@budibase/auth").db const { DocumentTypes } = require("../../db/utils") -async function redirect(ctx, method) { +async function redirect(ctx, method, path = "global") { const { devPath } = ctx.params const queryString = ctx.originalUrl.split("?")[1] || "" const response = await fetch( - checkSlashesInUrl(`${env.WORKER_URL}/api/global/${devPath}?${queryString}`), + checkSlashesInUrl( + `${env.WORKER_URL}/api/${path}/${devPath}?${queryString}` + ), request( ctx, { @@ -41,16 +43,22 @@ async function redirect(ctx, method) { ctx.cookies } -exports.redirectGet = async ctx => { - await redirect(ctx, "GET") +exports.buildRedirectGet = path => { + return async ctx => { + await redirect(ctx, "GET", path) + } } -exports.redirectPost = async ctx => { - await redirect(ctx, "POST") +exports.buildRedirectPost = path => { + return async ctx => { + await redirect(ctx, "POST", path) + } } -exports.redirectDelete = async ctx => { - await redirect(ctx, "DELETE") +exports.buildRedirectDelete = path => { + return async ctx => { + await redirect(ctx, "DELETE", path) + } } exports.clearLock = async ctx => { diff --git a/packages/server/src/api/routes/dev.js b/packages/server/src/api/routes/dev.js index 7612d332dd..0d9bd118aa 100644 --- a/packages/server/src/api/routes/dev.js +++ b/packages/server/src/api/routes/dev.js @@ -6,11 +6,16 @@ const { BUILDER } = require("@budibase/auth/permissions") const router = Router() -if (env.isDev() || env.isTest()) { +function redirectPath(path) { router - .get("/api/global/:devPath(.*)", controller.redirectGet) - .post("/api/global/:devPath(.*)", controller.redirectPost) - .delete("/api/global/:devPath(.*)", controller.redirectDelete) + .get(`/api/${path}/:devPath(.*)`, controller.buildRedirectGet(path)) + .post(`/api/${path}/:devPath(.*)`, controller.buildRedirectPost(path)) + .delete(`/api/${path}/:devPath(.*)`, controller.buildRedirectDelete(path)) +} + +if (env.isDev() || env.isTest()) { + redirectPath("global") + redirectPath("system") } router diff --git a/packages/server/src/utilities/rowProcessor/index.js b/packages/server/src/utilities/rowProcessor/index.js index 55af87bc13..7d4ae3016e 100644 --- a/packages/server/src/utilities/rowProcessor/index.js +++ b/packages/server/src/utilities/rowProcessor/index.js @@ -150,6 +150,10 @@ exports.processAutoColumn = processAutoColumn * @returns {object} The coerced value */ exports.coerce = (row, type) => { + // no coercion specified for type, skip it + if (!TYPE_TRANSFORM_MAP[type]) { + return row + } // eslint-disable-next-line no-prototype-builtins if (TYPE_TRANSFORM_MAP[type].hasOwnProperty(row)) { return TYPE_TRANSFORM_MAP[type][row]