mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 16:28:31 +00:00
* Collect only anonymous page views on published applications. * Explain why a published page is counted once when it opens.
67 lines
1.9 KiB
JavaScript
67 lines
1.9 KiB
JavaScript
import { BUILDER_PREVIEW_PATH_PREFIX } from '@baserow/modules/builder/utils/preview'
|
|
import { isBuilderPreviewHostname as isPreviewHostname } from '@baserow/modules/core/utils/publishedSite'
|
|
|
|
/**
|
|
* Make sure only baserow routes are available for instance public hostname.
|
|
*/
|
|
export const shouldRemoveRoute = (
|
|
route,
|
|
{ isWebFrontendHostname, isBuilderPreviewHostname, isBuilderPreviewRequest }
|
|
) => {
|
|
if (isWebFrontendHostname) {
|
|
const isPreviewRouteOnAnotherHost =
|
|
route.meta?.previewBuilderRoute && !isBuilderPreviewRequest
|
|
return route.meta?.publishedBuilderRoute || isPreviewRouteOnAnotherHost
|
|
}
|
|
|
|
if (isBuilderPreviewHostname) {
|
|
return !route.meta?.previewBuilderRoute
|
|
}
|
|
|
|
return !route.meta?.publishedBuilderRoute
|
|
}
|
|
|
|
export default defineNuxtPlugin({
|
|
name: 'router',
|
|
dependsOn: [
|
|
'is-web-frontend-hostname',
|
|
'core',
|
|
'builder',
|
|
'database',
|
|
'automation',
|
|
'dashboard',
|
|
// Should execute after other applications are loaded to remove all the
|
|
// unnecessary routes
|
|
],
|
|
|
|
setup(nuxtApp) {
|
|
const router = useRouter()
|
|
const runtimeConfig = useRuntimeConfig()
|
|
const { $isWebFrontendHostname } = nuxtApp
|
|
const requestUrl = useRequestURL()
|
|
const isBuilderPreviewHostname = isPreviewHostname(
|
|
requestUrl.hostname,
|
|
runtimeConfig.public
|
|
)
|
|
const isBuilderPreviewPath =
|
|
requestUrl.pathname === BUILDER_PREVIEW_PATH_PREFIX ||
|
|
requestUrl.pathname.startsWith(`${BUILDER_PREVIEW_PATH_PREFIX}/`)
|
|
const isBuilderPreviewRequest =
|
|
isBuilderPreviewHostname || isBuilderPreviewPath
|
|
|
|
// Ensure only routes for the current hostname role are available.
|
|
for (const r of router.getRoutes()) {
|
|
if (
|
|
shouldRemoveRoute(r, {
|
|
isWebFrontendHostname: $isWebFrontendHostname,
|
|
isBuilderPreviewHostname,
|
|
isBuilderPreviewRequest,
|
|
}) &&
|
|
router.hasRoute(r.name)
|
|
) {
|
|
router.removeRoute(r.name)
|
|
}
|
|
}
|
|
},
|
|
})
|