chore: uncomment out the example of a server component with local api running

This commit is contained in:
Paul Popus 2024-03-12 23:12:46 -03:00
parent 59293846cb
commit ed3563470c
3 changed files with 31 additions and 32 deletions

View File

@ -1,4 +1,4 @@
import path from "path";
import path from 'path'
// import { postgresAdapter } from '@payloadcms/db-postgres'
import {
AlignFeature,
@ -17,50 +17,50 @@ import {
RelationshipFeature,
UnorderedListFeature,
UploadFeature,
} from "@payloadcms/richtext-lexical";
} from '@payloadcms/richtext-lexical'
//import { slateEditor } from '@payloadcms/richtext-slate'
import { mongooseAdapter } from "@payloadcms/db-mongodb";
import { buildConfig } from "payload/config";
import sharp from "sharp";
import { fileURLToPath } from "url";
import { mongooseAdapter } from '@payloadcms/db-mongodb'
import { buildConfig } from 'payload/config'
import sharp from 'sharp'
import { fileURLToPath } from 'url'
const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
export default buildConfig({
//editor: slateEditor({}),
editor: lexicalEditor(),
collections: [
{
slug: "pages",
slug: 'pages',
admin: {
useAsTitle: "title",
useAsTitle: 'title',
},
fields: [
{
name: "title",
type: "text",
name: 'title',
type: 'text',
},
{
name: "content",
type: "richText",
name: 'content',
type: 'richText',
},
],
},
{
slug: "media",
slug: 'media',
upload: true,
fields: [
{
name: "text",
type: "text",
name: 'text',
type: 'text',
},
],
},
],
secret: process.env.PAYLOAD_SECRET || "",
secret: process.env.PAYLOAD_SECRET || '',
typescript: {
outputFile: path.resolve(dirname, "payload-types.ts"),
outputFile: path.resolve(dirname, 'payload-types.ts'),
},
// db: postgresAdapter({
// pool: {
@ -68,29 +68,29 @@ export default buildConfig({
// }
// }),
db: mongooseAdapter({
url: process.env.MONGODB_URI || "",
url: process.env.MONGODB_URI || '',
}),
admin: {
autoLogin: {
email: "dev@payloadcms.com",
password: "test",
email: 'dev@payloadcms.com',
password: 'test',
prefillOnly: true,
},
},
async onInit(payload) {
const existingUsers = await payload.find({
collection: "users",
collection: 'users',
limit: 1,
});
})
if (existingUsers.docs.length === 0) {
await payload.create({
collection: "users",
collection: 'users',
data: {
email: "dev@payloadcms.com",
password: "test",
email: 'dev@payloadcms.com',
password: 'test',
},
});
})
}
},
// Sharp is now an optional dependency -
@ -100,4 +100,4 @@ export default buildConfig({
// This is temporary - we may make an adapter pattern
// for this before reaching 3.0 stable
sharp,
});
})

View File

@ -36,8 +36,7 @@ const Page = () => {
contains an example of a custom route running the Local API.
</p>
{/* Commented out for now due to bug */}
{/* <Example /> */}
<Example />
<p>You can use the Local API in your server components like this:</p>
<pre>

View File

@ -4,7 +4,7 @@ import configPromise from '@payload-config'
const Example: React.FC = async () => {
const payload = await getPayload({ config: configPromise })
const url = payload.config.serverURL
const url = payload.getAdminURL()
return <div>The admin panel is running at: {url}</div>
}