Sites without users
JSON for client-side pages
access: 'visitor'access: 'public'useFetch
Data that your pages fetch in the browser, kept from being embedded by other sites.
Some pages load data in the browser: a store locator, a product filter, an events calendar. With access: 'visitor', other websites cannot pull that JSON into their own pages through their visitors' browsers.
server/api/stores.get.ts
import { defineBffHandler } from '#bff-guard'
export default defineBffHandler(async (event) => {
const { prefecture } = getQuery(event)
return await findStores(String(prefecture ?? ''))
})
pages/stores.vue
<script setup lang="ts">
const prefecture = ref('tokyo')
// server: false — fetched by the browser, so it is a page fetch.
const { data: stores } = await useFetch('/api/stores', {
query: { prefecture },
server: false,
})
</script>
The same data during SSR
If the page also renders the first result on the server, a visitor route would pass or fail depending on how the visitor arrived, because useFetch forwards the page request's Sec-Fetch-Site. The rendered page shows the data to anyone anyway, so make that route public instead:
server/api/stores.get.ts
export default defineBffHandler(handler, { access: 'public' })
Choose per route: 'visitor' for data the browser fetches, 'public' for data the server renders into the page.