Merge pull request #3003 from Budibase/fix/2998
Fix issue with template call when no internet connection available
This commit is contained in:
commit
2bd4bc8a90
|
@ -150,7 +150,6 @@
|
||||||
showCancelButton={false}
|
showCancelButton={false}
|
||||||
showCloseIcon={false}
|
showCloseIcon={false}
|
||||||
>
|
>
|
||||||
<Body size="M">Select a template below, or start from scratch.</Body>
|
|
||||||
<TemplateList
|
<TemplateList
|
||||||
onSelect={selected => {
|
onSelect={selected => {
|
||||||
if (!selected) {
|
if (!selected) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import { Heading, Layout, Icon } from "@budibase/bbui"
|
import { Heading, Layout, Icon, Body } from "@budibase/bbui"
|
||||||
import Spinner from "components/common/Spinner.svelte"
|
import Spinner from "components/common/Spinner.svelte"
|
||||||
import api from "builderStore/api"
|
import api from "builderStore/api"
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
async function fetchTemplates() {
|
async function fetchTemplates() {
|
||||||
const response = await api.get("/api/templates?type=app")
|
const response = await api.get("/api/templates?type=app")
|
||||||
|
console.log("Responded")
|
||||||
return await response.json()
|
return await response.json()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +20,11 @@
|
||||||
<Spinner size="30" />
|
<Spinner size="30" />
|
||||||
</div>
|
</div>
|
||||||
{:then templates}
|
{:then templates}
|
||||||
|
{#if templates?.length > 0}
|
||||||
|
<Body size="M">Select a template below, or start from scratch.</Body>
|
||||||
|
{:else}
|
||||||
|
<Body size="M">Start your app from scratch below.</Body>
|
||||||
|
{/if}
|
||||||
<div class="templates">
|
<div class="templates">
|
||||||
{#each templates as template}
|
{#each templates as template}
|
||||||
<div class="template" on:click={() => onSelect(template)}>
|
<div class="template" on:click={() => onSelect(template)}>
|
||||||
|
|
|
@ -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 => {
|
||||||
|
|
|
@ -7,11 +7,23 @@ const DEFAULT_TEMPLATES_BUCKET =
|
||||||
|
|
||||||
exports.fetch = async function (ctx) {
|
exports.fetch = async function (ctx) {
|
||||||
const { type = "app" } = ctx.query
|
const { type = "app" } = ctx.query
|
||||||
const response = await fetch(
|
let response,
|
||||||
`https://${DEFAULT_TEMPLATES_BUCKET}/manifest.json`
|
error = false
|
||||||
)
|
try {
|
||||||
|
response = await fetch(`https://${DEFAULT_TEMPLATES_BUCKET}/manifest.json`)
|
||||||
|
if (response.status !== 200) {
|
||||||
|
error = true
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
error = true
|
||||||
|
}
|
||||||
|
// if there is an error, simply return no templates
|
||||||
|
if (!error && response) {
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
ctx.body = Object.values(json.templates[type])
|
ctx.body = Object.values(json.templates[type])
|
||||||
|
} else {
|
||||||
|
ctx.body = []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// can't currently test this, have to ignore from coverage
|
// can't currently test this, have to ignore from coverage
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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]
|
||||||
|
|
Loading…
Reference in New Issue