Supports live preview conditions. This is essentially access control for
live preview, where you may want to restrict who can use it based on
certain criteria, such as the current user or document data.
To do this, simply return null or undefined from your live preview url
functions:
```ts
url: ({ req }) => (req.user?.role === 'admin' ? '/hello-world' : null)
```
This is also useful for pages which derive their URL from document data,
e.g. a slug field, do not attempt to render the live preview window
until the URL is fully formatted.
For example, if you have a page in your front-end with the URL structure
of `/posts/[slug]`, the slug field is required before the page can
properly load. However, if the slug is not a required field, or when
drafts and/or autosave is enabled, the slug field might not yet have
data, leading to `/posts/undefined` or similar.
```ts
url: ({ data }) => data?.slug ? `/${data.slug}` : null
```
---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
- https://app.asana.com/0/0/1211513433305000
71 lines
2.2 KiB
TypeScript
71 lines
2.2 KiB
TypeScript
import { fileURLToPath } from 'node:url'
|
|
import path from 'path'
|
|
const filename = fileURLToPath(import.meta.url)
|
|
const dirname = path.dirname(filename)
|
|
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
|
|
import { MediaBlock } from './blocks/MediaBlock/index.js'
|
|
import { Categories } from './collections/Categories.js'
|
|
import { CollectionLevelConfig } from './collections/CollectionLevelConfig.js'
|
|
import { Media } from './collections/Media.js'
|
|
import { NoURLCollection } from './collections/NoURL.js'
|
|
import { Pages } from './collections/Pages.js'
|
|
import { Posts } from './collections/Posts.js'
|
|
import { SSR } from './collections/SSR.js'
|
|
import { SSRAutosave } from './collections/SSRAutosave.js'
|
|
import { StaticURLCollection } from './collections/StaticURL.js'
|
|
import { Tenants } from './collections/Tenants.js'
|
|
import { Users } from './collections/Users.js'
|
|
import { Footer } from './globals/Footer.js'
|
|
import { Header } from './globals/Header.js'
|
|
import { seed } from './seed/index.js'
|
|
import {
|
|
desktopBreakpoint,
|
|
mobileBreakpoint,
|
|
pagesSlug,
|
|
postsSlug,
|
|
ssrAutosavePagesSlug,
|
|
ssrPagesSlug,
|
|
} from './shared.js'
|
|
import { formatLivePreviewURL } from './utilities/formatLivePreviewURL.js'
|
|
|
|
export default buildConfigWithDefaults({
|
|
localization: {
|
|
defaultLocale: 'en',
|
|
locales: ['en', 'es'],
|
|
},
|
|
admin: {
|
|
importMap: {
|
|
baseDir: path.resolve(dirname),
|
|
},
|
|
livePreview: {
|
|
// You can define any of these properties on a per collection or global basis
|
|
// The Live Preview config cascades from the top down, properties are inherited from here
|
|
url: formatLivePreviewURL,
|
|
breakpoints: [mobileBreakpoint, desktopBreakpoint],
|
|
collections: [pagesSlug, postsSlug, ssrPagesSlug, ssrAutosavePagesSlug],
|
|
globals: ['header', 'footer'],
|
|
},
|
|
},
|
|
cors: ['http://localhost:3000', 'http://localhost:3001'],
|
|
csrf: ['http://localhost:3000', 'http://localhost:3001'],
|
|
collections: [
|
|
Users,
|
|
Pages,
|
|
Posts,
|
|
SSR,
|
|
SSRAutosave,
|
|
Tenants,
|
|
Categories,
|
|
Media,
|
|
CollectionLevelConfig,
|
|
StaticURLCollection,
|
|
NoURLCollection,
|
|
],
|
|
globals: [Header, Footer],
|
|
onInit: seed,
|
|
typescript: {
|
|
outputFile: path.resolve(dirname, 'payload-types.ts'),
|
|
},
|
|
blocks: [MediaBlock],
|
|
})
|