From 3d533d9f137749cc88a8088ce84f74bbd1ee6e26 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Wed, 26 Jan 2022 13:39:40 +0000 Subject: [PATCH] Handle undefined url --- packages/builder/src/helpers/validation/yup/app.js | 2 +- packages/builder/src/pages/builder/apps/index.svelte | 6 +++++- packages/builder/src/pages/builder/portal/apps/index.svelte | 6 +++++- packages/server/src/api/controllers/static/index.js | 4 +++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/builder/src/helpers/validation/yup/app.js b/packages/builder/src/helpers/validation/yup/app.js index 7944dccd30..de0f86446c 100644 --- a/packages/builder/src/helpers/validation/yup/app.js +++ b/packages/builder/src/helpers/validation/yup/app.js @@ -51,7 +51,7 @@ export const url = (validation, { apps, currentApp } = { apps: [] }) => { } return !apps .map(app => app.url) - .some(appUrl => appUrl.toLowerCase() === value.toLowerCase()) + .some(appUrl => appUrl?.toLowerCase() === value.toLowerCase()) } ) .test("valid-url", "Not a valid URL", value => { diff --git a/packages/builder/src/pages/builder/apps/index.svelte b/packages/builder/src/pages/builder/apps/index.svelte index 4d83531ed6..c98e749e45 100644 --- a/packages/builder/src/pages/builder/apps/index.svelte +++ b/packages/builder/src/pages/builder/apps/index.svelte @@ -41,7 +41,11 @@ ) function getUrl(app) { - return `/app${app.url}` + if (app.url) { + return `/app${app.url}` + } else { + return `/${app.prodId}` + } } diff --git a/packages/builder/src/pages/builder/portal/apps/index.svelte b/packages/builder/src/pages/builder/portal/apps/index.svelte index abbf48d0da..faa57e5df3 100644 --- a/packages/builder/src/pages/builder/portal/apps/index.svelte +++ b/packages/builder/src/pages/builder/portal/apps/index.svelte @@ -161,7 +161,11 @@ } const viewApp = app => { - window.open(`/app${app.url}`) + if (app.url) { + window.open(`/app${app.url}`) + } else { + window.open(`/${app.prodId}`) + } } const editApp = app => { diff --git a/packages/server/src/api/controllers/static/index.js b/packages/server/src/api/controllers/static/index.js index 7bfce0bee0..08b84e4c3d 100644 --- a/packages/server/src/api/controllers/static/index.js +++ b/packages/server/src/api/controllers/static/index.js @@ -43,7 +43,9 @@ async function getAppIdFromUrl(ctx) { // search prod apps for a url that matches, exclude dev where id is always used const apps = await getAllApps(CouchDB, { dev: false }) - const app = apps.filter(a => a.url.toLowerCase() === possibleAppUrl)[0] + const app = apps.filter( + a => a.url && a.url.toLowerCase() === possibleAppUrl + )[0] if (app && app.appId) { return app.appId