-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayload.config.ts
147 lines (142 loc) · 5.25 KB
/
payload.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import { webpackBundler } from '@payloadcms/bundler-webpack' // bundler-import
import { mongooseAdapter } from '@payloadcms/db-mongodb' // database-adapter-import
import { payloadCloud } from '@payloadcms/plugin-cloud'
import nestedDocs from '@payloadcms/plugin-nested-docs'
import redirects from '@payloadcms/plugin-redirects'
import seo from '@payloadcms/plugin-seo'
import type { GenerateTitle } from '@payloadcms/plugin-seo/types'
import stripePlugin from '@payloadcms/plugin-stripe'
import { slateEditor } from '@payloadcms/richtext-slate' // editor-import
import dotenv from 'dotenv'
import path from 'path'
import { buildConfig } from 'payload/config'
import Categories from './collections/Categories'
import { Media } from './collections/Media'
import { Orders } from './collections/Orders'
import { Pages } from './collections/Pages'
import Products from './collections/Products'
import Users from './collections/Users'
import BeforeDashboard from './components/BeforeDashboard'
import BeforeLogin from './components/BeforeLogin'
import { createPaymentIntent } from './endpoints/create-payment-intent'
import { customersProxy } from './endpoints/customers'
import { productsProxy } from './endpoints/products'
import { seed } from './endpoints/seed'
import { Footer } from './globals/Footer'
import { Header } from './globals/Header'
import { Settings } from './globals/Settings'
import { priceUpdated } from './stripe/webhooks/priceUpdated'
import { productUpdated } from './stripe/webhooks/productUpdated'
const generateTitle: GenerateTitle = () => {
return 'My Store'
}
const mockModulePath = path.resolve(__dirname, './emptyModuleMock.js')
dotenv.config({
path: path.resolve(__dirname, '../../.env'),
})
export default buildConfig({
admin: {
user: Users.slug,
bundler: webpackBundler(), // bundler-config
components: {
// The `BeforeLogin` component renders a message that you see while logging into your admin panel.
// Feel free to delete this at any time. Simply remove the line below and the import `BeforeLogin` statement on line 15.
beforeLogin: [BeforeLogin],
// The `BeforeDashboard` component renders the 'welcome' block that you see after logging into your admin panel.
// Feel free to delete this at any time. Simply remove the line below and the import `BeforeDashboard` statement on line 15.
beforeDashboard: [BeforeDashboard],
},
webpack: config => {
return {
...config,
resolve: {
...config.resolve,
alias: {
...config.resolve?.alias,
dotenv: path.resolve(__dirname, './dotenv.js'),
[path.resolve(__dirname, 'collections/Products/hooks/beforeChange')]: mockModulePath,
[path.resolve(__dirname, 'collections/Users/hooks/createStripeCustomer')]:
mockModulePath,
[path.resolve(__dirname, 'collections/Users/endpoints/customer')]: mockModulePath,
[path.resolve(__dirname, 'endpoints/create-payment-intent')]: mockModulePath,
[path.resolve(__dirname, 'endpoints/customers')]: mockModulePath,
[path.resolve(__dirname, 'endpoints/products')]: mockModulePath,
[path.resolve(__dirname, 'endpoints/seed')]: mockModulePath,
stripe: mockModulePath,
express: mockModulePath,
},
},
}
},
},
editor: slateEditor({}), // editor-config
// database-adapter-config-start
db: mongooseAdapter({
url: process.env.DATABASE_URI,
}),
// database-adapter-config-end
serverURL: process.env.PAYLOAD_PUBLIC_SERVER_URL,
collections: [Pages, Products, Orders, Media, Categories, Users],
globals: [Settings, Header, Footer],
typescript: {
outputFile: path.resolve(__dirname, 'payload-types.ts'),
},
graphQL: {
schemaOutputFile: path.resolve(__dirname, 'generated-schema.graphql'),
},
cors: ['https://checkout.stripe.com', process.env.PAYLOAD_PUBLIC_SERVER_URL || ''].filter(
Boolean,
),
csrf: ['https://checkout.stripe.com', process.env.PAYLOAD_PUBLIC_SERVER_URL || ''].filter(
Boolean,
),
endpoints: [
{
path: '/create-payment-intent',
method: 'post',
handler: createPaymentIntent,
},
{
path: '/stripe/customers',
method: 'get',
handler: customersProxy,
},
{
path: '/stripe/products',
method: 'get',
handler: productsProxy,
},
// The seed endpoint is used to populate the database with some example data
// You should delete this endpoint before deploying your site to production
{
path: '/seed',
method: 'get',
handler: seed,
},
],
plugins: [
stripePlugin({
stripeSecretKey: process.env.STRIPE_SECRET_KEY || '',
isTestKey: Boolean(process.env.PAYLOAD_PUBLIC_STRIPE_IS_TEST_KEY),
stripeWebhooksEndpointSecret: process.env.STRIPE_WEBHOOKS_SIGNING_SECRET,
rest: false,
webhooks: {
'product.created': productUpdated,
'product.updated': productUpdated,
'price.updated': priceUpdated,
},
}),
redirects({
collections: ['pages', 'products'],
}),
nestedDocs({
collections: ['categories'],
}),
seo({
collections: ['pages', 'products'],
generateTitle,
uploadsCollection: 'media',
}),
payloadCloud(),
],
})