1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-03-15 13:04:50 +00:00
bramw_baserow/web-frontend/modules/builder/pages/publicPage.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

86 lines
2.1 KiB
Vue
Raw Normal View History

<template>
2023-05-11 15:27:17 +00:00
<PublicPage :page="page" :path="path" :params="params" />
</template>
<script>
import PublicPage from '@baserow/modules/builder/components/page/PublicPage'
import { resolveApplicationRoute } from '@baserow/modules/builder/utils/routing'
export default {
components: { PublicPage },
2023-05-11 15:27:17 +00:00
provide() {
return { builder: this.builder, mode: this.mode }
},
async asyncData(context) {
let builder = context.store.getters['publicBuilder/getBuilder']
2023-05-11 15:27:17 +00:00
let mode = 'public'
const builderId = context.route.params.builderId
if (!builder) {
try {
if (builderId) {
// We have the builderId in the params so this is a preview
// Must fetch the builder instance by this Id.
await context.store.dispatch('publicBuilder/fetchById', {
builderId,
})
} else {
// We don't have the builderId so it's a public page.
// Must fetch the builder instance by domain name.
const host = process.server
? context.req.headers.host
: window.location.host
const domain = new URL(`http://${host}`).hostname
await context.store.dispatch('publicBuilder/fetchByDomain', {
domain,
})
}
builder = context.store.getters['publicBuilder/getBuilder']
} catch (e) {
return context.error({
statusCode: 404,
message: context.app.i18n.t('publicPage.siteNotFound'),
})
}
}
2023-05-11 15:27:17 +00:00
if (builderId) {
mode = 'preview'
}
const found = resolveApplicationRoute(
builder.pages,
context.route.params.pathMatch
)
// Handle 404
if (!found) {
return context.error({
statusCode: 404,
message: context.app.i18n.t('publicPage.pageNotFound'),
})
}
const [page, path, params] = found
return {
builder,
page,
path,
params,
2023-05-11 15:27:17 +00:00
mode,
}
},
2023-06-27 09:29:02 +00:00
head() {
return {
titleTemplate: '',
title: this.page.name,
bodyAttrs: {
class: 'public-page',
},
}
},
}
</script>