2023-04-27 06:48:58 +00:00
|
|
|
<template>
|
2023-05-11 15:27:17 +00:00
|
|
|
<PublicPage :page="page" :path="path" :params="params" />
|
2023-04-27 06:48:58 +00:00
|
|
|
</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 }
|
|
|
|
},
|
2023-04-27 06:48:58 +00:00
|
|
|
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
|
2023-04-27 06:48:58 +00:00
|
|
|
|
|
|
|
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'
|
|
|
|
}
|
|
|
|
|
2023-04-27 06:48:58 +00:00
|
|
|
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-04-27 06:48:58 +00:00
|
|
|
}
|
|
|
|
},
|
2023-06-27 09:29:02 +00:00
|
|
|
head() {
|
|
|
|
return {
|
|
|
|
titleTemplate: '',
|
|
|
|
title: this.page.name,
|
|
|
|
bodyAttrs: {
|
|
|
|
class: 'public-page',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2023-04-27 06:48:58 +00:00
|
|
|
}
|
|
|
|
</script>
|