Fixing some issues which were causing errors during the cypress test runs, such as not redirect /api/system/ requests to the worker.

This commit is contained in:
mike12345567 2021-10-14 16:16:20 +01:00
parent 0539f1a429
commit 2d94d93f5b
3 changed files with 29 additions and 12 deletions

View File

@ -7,11 +7,13 @@ const { clearLock } = require("../../utilities/redis")
const { Replication } = require("@budibase/auth").db const { Replication } = require("@budibase/auth").db
const { DocumentTypes } = require("../../db/utils") const { DocumentTypes } = require("../../db/utils")
async function redirect(ctx, method) { async function redirect(ctx, method, path = "global") {
const { devPath } = ctx.params const { devPath } = ctx.params
const queryString = ctx.originalUrl.split("?")[1] || "" const queryString = ctx.originalUrl.split("?")[1] || ""
const response = await fetch( const response = await fetch(
checkSlashesInUrl(`${env.WORKER_URL}/api/global/${devPath}?${queryString}`), checkSlashesInUrl(
`${env.WORKER_URL}/api/${path}/${devPath}?${queryString}`
),
request( request(
ctx, ctx,
{ {
@ -41,16 +43,22 @@ async function redirect(ctx, method) {
ctx.cookies ctx.cookies
} }
exports.redirectGet = async ctx => { exports.buildRedirectGet = path => {
await redirect(ctx, "GET") return async ctx => {
await redirect(ctx, "GET", path)
}
} }
exports.redirectPost = async ctx => { exports.buildRedirectPost = path => {
await redirect(ctx, "POST") return async ctx => {
await redirect(ctx, "POST", path)
}
} }
exports.redirectDelete = async ctx => { exports.buildRedirectDelete = path => {
await redirect(ctx, "DELETE") return async ctx => {
await redirect(ctx, "DELETE", path)
}
} }
exports.clearLock = async ctx => { exports.clearLock = async ctx => {

View File

@ -6,11 +6,16 @@ const { BUILDER } = require("@budibase/auth/permissions")
const router = Router() const router = Router()
if (env.isDev() || env.isTest()) { function redirectPath(path) {
router router
.get("/api/global/:devPath(.*)", controller.redirectGet) .get(`/api/${path}/:devPath(.*)`, controller.buildRedirectGet(path))
.post("/api/global/:devPath(.*)", controller.redirectPost) .post(`/api/${path}/:devPath(.*)`, controller.buildRedirectPost(path))
.delete("/api/global/:devPath(.*)", controller.redirectDelete) .delete(`/api/${path}/:devPath(.*)`, controller.buildRedirectDelete(path))
}
if (env.isDev() || env.isTest()) {
redirectPath("global")
redirectPath("system")
} }
router router

View File

@ -150,6 +150,10 @@ exports.processAutoColumn = processAutoColumn
* @returns {object} The coerced value * @returns {object} The coerced value
*/ */
exports.coerce = (row, type) => { 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 // eslint-disable-next-line no-prototype-builtins
if (TYPE_TRANSFORM_MAP[type].hasOwnProperty(row)) { if (TYPE_TRANSFORM_MAP[type].hasOwnProperty(row)) {
return TYPE_TRANSFORM_MAP[type][row] return TYPE_TRANSFORM_MAP[type][row]