chore(examples/custom-server): migrates to 2.0 (#3509)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
MONGODB_URI=mongodb://127.0.0.1/payload-example-custom-server
|
DATABASE_URI=mongodb://127.0.0.1/payload-example-custom-server
|
||||||
PAYLOAD_SECRET=PAYLOAD_CUSTOM_SERVER_EXAMPLE_SECRET_KEY
|
PAYLOAD_SECRET=PAYLOAD_CUSTOM_SERVER_EXAMPLE_SECRET_KEY
|
||||||
PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3000
|
PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3000
|
||||||
NEXT_PUBLIC_SERVER_URL=http://localhost:3000
|
NEXT_PUBLIC_PAYLOAD_URL=http://localhost:3000
|
||||||
PAYLOAD_PUBLIC_SEED=true
|
PAYLOAD_PUBLIC_SEED=true
|
||||||
PAYLOAD_DROP_DATABASE=true
|
PAYLOAD_DROP_DATABASE=true
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ module.exports = {
|
|||||||
reactStrictMode: true,
|
reactStrictMode: true,
|
||||||
swcMinify: true,
|
swcMinify: true,
|
||||||
images: {
|
images: {
|
||||||
domains: ['localhost', process.env.NEXT_PUBLIC_SERVER_URL],
|
domains: ['localhost', process.env.NEXT_PUBLIC_PAYLOAD_URL],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,9 @@
|
|||||||
"lint:fix": "eslint --fix --ext .ts,.tsx src"
|
"lint:fix": "eslint --fix --ext .ts,.tsx src"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@payloadcms/bundler-webpack": "^1.0.0-beta.5",
|
||||||
|
"@payloadcms/db-mongodb": "^1.0.0-beta.8",
|
||||||
|
"@payloadcms/richtext-slate": "^1.0.0-beta.4",
|
||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"escape-html": "^1.0.3",
|
"escape-html": "^1.0.3",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
|
|||||||
3
examples/custom-server/src/dotenv.js
Normal file
3
examples/custom-server/src/dotenv.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
config: () => null,
|
||||||
|
}
|
||||||
@@ -22,10 +22,6 @@ interface Args {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const getPayloadClient = async ({ initOptions, seed }: Args = {}): Promise<Payload> => {
|
export const getPayloadClient = async ({ initOptions, seed }: Args = {}): Promise<Payload> => {
|
||||||
if (!process.env.MONGODB_URI) {
|
|
||||||
throw new Error('MONGODB_URI environment variable is missing')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!process.env.PAYLOAD_SECRET) {
|
if (!process.env.PAYLOAD_SECRET) {
|
||||||
throw new Error('PAYLOAD_SECRET environment variable is missing')
|
throw new Error('PAYLOAD_SECRET environment variable is missing')
|
||||||
}
|
}
|
||||||
@@ -36,7 +32,6 @@ export const getPayloadClient = async ({ initOptions, seed }: Args = {}): Promis
|
|||||||
|
|
||||||
if (!cached.promise) {
|
if (!cached.promise) {
|
||||||
cached.promise = payload.init({
|
cached.promise = payload.init({
|
||||||
mongoURL: process.env.MONGODB_URI,
|
|
||||||
secret: process.env.PAYLOAD_SECRET,
|
secret: process.env.PAYLOAD_SECRET,
|
||||||
local: initOptions?.express ? false : true,
|
local: initOptions?.express ? false : true,
|
||||||
...(initOptions || {}),
|
...(initOptions || {}),
|
||||||
|
|||||||
@@ -8,31 +8,70 @@
|
|||||||
|
|
||||||
export interface Config {
|
export interface Config {
|
||||||
collections: {
|
collections: {
|
||||||
pages: Page;
|
pages: Page
|
||||||
users: User;
|
users: User
|
||||||
};
|
'payload-preferences': PayloadPreference
|
||||||
globals: {};
|
'payload-migrations': PayloadMigration
|
||||||
|
}
|
||||||
|
globals: {}
|
||||||
}
|
}
|
||||||
export interface Page {
|
export interface Page {
|
||||||
id: string;
|
id: string
|
||||||
title: string;
|
title: string
|
||||||
richText?: {
|
richText?: {
|
||||||
[k: string]: unknown;
|
[k: string]: unknown
|
||||||
}[];
|
}[]
|
||||||
slug?: string;
|
slug?: string
|
||||||
updatedAt: string;
|
updatedAt: string
|
||||||
createdAt: string;
|
createdAt: string
|
||||||
}
|
}
|
||||||
export interface User {
|
export interface User {
|
||||||
id: string;
|
id: string
|
||||||
updatedAt: string;
|
updatedAt: string
|
||||||
createdAt: string;
|
createdAt: string
|
||||||
email: string;
|
email: string
|
||||||
resetPasswordToken?: string;
|
resetPasswordToken?: string
|
||||||
resetPasswordExpiration?: string;
|
resetPasswordExpiration?: string
|
||||||
salt?: string;
|
salt?: string
|
||||||
hash?: string;
|
hash?: string
|
||||||
loginAttempts?: number;
|
loginAttempts?: number
|
||||||
lockUntil?: string;
|
lockUntil?: string
|
||||||
password?: string;
|
password?: string
|
||||||
|
}
|
||||||
|
export interface PayloadPreference {
|
||||||
|
id: string
|
||||||
|
user: {
|
||||||
|
relationTo: 'users'
|
||||||
|
value: string | User
|
||||||
|
}
|
||||||
|
key?: string
|
||||||
|
value?:
|
||||||
|
| {
|
||||||
|
[k: string]: unknown
|
||||||
|
}
|
||||||
|
| unknown[]
|
||||||
|
| string
|
||||||
|
| number
|
||||||
|
| boolean
|
||||||
|
| null
|
||||||
|
updatedAt: string
|
||||||
|
createdAt: string
|
||||||
|
}
|
||||||
|
export interface PayloadMigration {
|
||||||
|
id: string
|
||||||
|
name?: string
|
||||||
|
batch?: number
|
||||||
|
updatedAt: string
|
||||||
|
createdAt: string
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module 'payload' {
|
||||||
|
export interface GeneratedTypes {
|
||||||
|
collections: {
|
||||||
|
pages: Page
|
||||||
|
users: User
|
||||||
|
'payload-preferences': PayloadPreference
|
||||||
|
'payload-migrations': PayloadMigration
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
import { webpackBundler } from '@payloadcms/bundler-webpack'
|
||||||
|
import { mongooseAdapter } from '@payloadcms/db-mongodb'
|
||||||
|
import { slateEditor } from '@payloadcms/richtext-slate'
|
||||||
import dotenv from 'dotenv'
|
import dotenv from 'dotenv'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
|
||||||
@@ -14,10 +17,25 @@ export default buildConfig({
|
|||||||
serverURL: process.env.PAYLOAD_PUBLIC_SERVER_URL || '',
|
serverURL: process.env.PAYLOAD_PUBLIC_SERVER_URL || '',
|
||||||
collections: [Pages],
|
collections: [Pages],
|
||||||
admin: {
|
admin: {
|
||||||
|
bundler: webpackBundler(),
|
||||||
components: {
|
components: {
|
||||||
beforeLogin: [BeforeLogin],
|
beforeLogin: [BeforeLogin],
|
||||||
},
|
},
|
||||||
|
webpack: config => ({
|
||||||
|
...config,
|
||||||
|
resolve: {
|
||||||
|
...config.resolve,
|
||||||
|
alias: {
|
||||||
|
...config.resolve.alias,
|
||||||
|
dotenv: path.resolve(__dirname, './dotenv.js'),
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
editor: slateEditor({}),
|
||||||
|
db: mongooseAdapter({
|
||||||
|
url: process.env.DATABASE_URI,
|
||||||
|
}),
|
||||||
typescript: {
|
typescript: {
|
||||||
outputFile: path.resolve(__dirname, 'payload-types.ts'),
|
outputFile: path.resolve(__dirname, 'payload-types.ts'),
|
||||||
},
|
},
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user