chore: rolls back next config testing
This commit is contained in:
@@ -3,9 +3,7 @@
|
||||
import config from '@payload-config'
|
||||
import { REST_DELETE, REST_GET, REST_PATCH, REST_POST } from '@payloadcms/next/routes'
|
||||
|
||||
export const GET = async (request: Request, options: { params: { slug: string[] } }) => {
|
||||
return REST_GET({ config, options, request })
|
||||
}
|
||||
export const GET = REST_GET(config)
|
||||
export const POST = REST_POST(config)
|
||||
export const DELETE = REST_DELETE(config)
|
||||
export const PATCH = REST_PATCH(config)
|
||||
|
||||
@@ -146,152 +146,140 @@ const RouteNotFoundResponse = (slug: string[]) =>
|
||||
{ status: httpStatus.NOT_FOUND },
|
||||
)
|
||||
|
||||
type GetArgs = {
|
||||
config: Promise<SanitizedConfig> | SanitizedConfig
|
||||
options: {
|
||||
params: {
|
||||
slug: string[]
|
||||
}
|
||||
}
|
||||
request: Request
|
||||
}
|
||||
export const GET =
|
||||
(config: Promise<SanitizedConfig> | SanitizedConfig) =>
|
||||
async (request: Request, { params: { slug } }: { params: { slug: string[] } }) => {
|
||||
const [slug1, slug2, slug3, slug4] = slug
|
||||
let req: PayloadRequest
|
||||
let res: Response
|
||||
let collection: Collection
|
||||
|
||||
export const GET = async ({
|
||||
config,
|
||||
options: {
|
||||
params: { slug },
|
||||
},
|
||||
request,
|
||||
}: GetArgs) => {
|
||||
const [slug1, slug2, slug3, slug4] = slug
|
||||
let req: PayloadRequest
|
||||
let res: Response
|
||||
let collection: Collection
|
||||
try {
|
||||
req = await createPayloadRequest({
|
||||
config,
|
||||
params: {
|
||||
collection: slug1,
|
||||
},
|
||||
request,
|
||||
})
|
||||
|
||||
try {
|
||||
req = await createPayloadRequest({
|
||||
config,
|
||||
params: {
|
||||
collection: slug1,
|
||||
},
|
||||
request,
|
||||
})
|
||||
|
||||
const disableEndpoints = endpointsAreDisabled({
|
||||
endpoints: req.payload.config.endpoints,
|
||||
request,
|
||||
})
|
||||
if (disableEndpoints) return disableEndpoints
|
||||
|
||||
collection = req.payload.collections?.[slug1]
|
||||
|
||||
if (collection) {
|
||||
const disableEndpoints = endpointsAreDisabled({
|
||||
endpoints: collection.config.endpoints,
|
||||
endpoints: req.payload.config.endpoints,
|
||||
request,
|
||||
})
|
||||
if (disableEndpoints) return disableEndpoints
|
||||
|
||||
collection = req.payload.collections?.[slug1]
|
||||
|
||||
if (collection) {
|
||||
const disableEndpoints = endpointsAreDisabled({
|
||||
endpoints: collection.config.endpoints,
|
||||
request,
|
||||
})
|
||||
if (disableEndpoints) return disableEndpoints
|
||||
|
||||
const customEndpointResponse = await handleCustomEndpoints({
|
||||
endpoints: collection.config.endpoints,
|
||||
entitySlug: slug1,
|
||||
payloadRequest: req,
|
||||
})
|
||||
if (customEndpointResponse) return customEndpointResponse
|
||||
|
||||
switch (slug.length) {
|
||||
case 1:
|
||||
// /:collection
|
||||
res = await endpoints.collection.GET.find({ collection, req })
|
||||
break
|
||||
case 2:
|
||||
if (slug2 in endpoints.collection.GET) {
|
||||
// /:collection/init
|
||||
// /:collection/me
|
||||
// /:collection/versions
|
||||
res = await (endpoints.collection.GET[slug2] as CollectionRouteHandler)({
|
||||
collection,
|
||||
req,
|
||||
})
|
||||
} else {
|
||||
// /:collection/:id
|
||||
res = await endpoints.collection.GET.findByID({ id: slug2, collection, req })
|
||||
}
|
||||
break
|
||||
case 3:
|
||||
if (`doc-${slug2}-by-id` in endpoints.collection.GET) {
|
||||
// /:collection/access/:id
|
||||
// /:collection/versions/:id
|
||||
res = await (
|
||||
endpoints.collection.GET[`doc-${slug2}-by-id`] as CollectionRouteHandlerWithID
|
||||
)({ id: slug3, collection, req })
|
||||
}
|
||||
break
|
||||
}
|
||||
} else if (slug1 === 'globals') {
|
||||
const globalConfig = req.payload.config.globals.find((global) => global.slug === slug2)
|
||||
|
||||
const disableEndpoints = endpointsAreDisabled({
|
||||
endpoints: globalConfig.endpoints,
|
||||
request,
|
||||
})
|
||||
if (disableEndpoints) return disableEndpoints
|
||||
|
||||
const customEndpointResponse = await handleCustomEndpoints({
|
||||
endpoints: globalConfig.endpoints,
|
||||
entitySlug: `${slug1}/${slug2}`,
|
||||
payloadRequest: req,
|
||||
})
|
||||
if (customEndpointResponse) return customEndpointResponse
|
||||
|
||||
switch (slug.length) {
|
||||
case 2:
|
||||
// /globals/:slug
|
||||
res = await endpoints.global.GET.findOne({ globalConfig, req })
|
||||
break
|
||||
case 3:
|
||||
if (`doc-${slug3}` in endpoints.global.GET) {
|
||||
// /globals/:slug/access
|
||||
// /globals/:slug/versions
|
||||
res = await (endpoints.global.GET?.[`doc-${slug3}`] as GlobalRouteHandler)({
|
||||
globalConfig,
|
||||
req,
|
||||
})
|
||||
}
|
||||
break
|
||||
case 4:
|
||||
if (`doc-${slug3}-by-id` in endpoints.global.GET) {
|
||||
// /globals/:slug/versions/:id
|
||||
res = await (
|
||||
endpoints.global.GET?.[`doc-${slug3}-by-id`] as GlobalRouteHandlerWithID
|
||||
)({
|
||||
id: slug4,
|
||||
globalConfig,
|
||||
req,
|
||||
})
|
||||
}
|
||||
break
|
||||
}
|
||||
} else if (slug.length === 1 && slug1 in endpoints.root.GET) {
|
||||
res = await endpoints.root.GET[slug1]({ req })
|
||||
}
|
||||
|
||||
if (res instanceof Response) return res
|
||||
|
||||
// root routes
|
||||
const customEndpointResponse = await handleCustomEndpoints({
|
||||
endpoints: collection.config.endpoints,
|
||||
entitySlug: slug1,
|
||||
endpoints: req.payload.config.endpoints,
|
||||
payloadRequest: req,
|
||||
})
|
||||
if (customEndpointResponse) return customEndpointResponse
|
||||
|
||||
switch (slug.length) {
|
||||
case 1:
|
||||
// /:collection
|
||||
res = await endpoints.collection.GET.find({ collection, req })
|
||||
break
|
||||
case 2:
|
||||
if (slug2 in endpoints.collection.GET) {
|
||||
// /:collection/init
|
||||
// /:collection/me
|
||||
// /:collection/versions
|
||||
res = await (endpoints.collection.GET[slug2] as CollectionRouteHandler)({
|
||||
collection,
|
||||
req,
|
||||
})
|
||||
} else {
|
||||
// /:collection/:id
|
||||
res = await endpoints.collection.GET.findByID({ id: slug2, collection, req })
|
||||
}
|
||||
break
|
||||
case 3:
|
||||
if (`doc-${slug2}-by-id` in endpoints.collection.GET) {
|
||||
// /:collection/access/:id
|
||||
// /:collection/versions/:id
|
||||
res = await (
|
||||
endpoints.collection.GET[`doc-${slug2}-by-id`] as CollectionRouteHandlerWithID
|
||||
)({ id: slug3, collection, req })
|
||||
}
|
||||
break
|
||||
}
|
||||
} else if (slug1 === 'globals') {
|
||||
const globalConfig = req.payload.config.globals.find((global) => global.slug === slug2)
|
||||
|
||||
const disableEndpoints = endpointsAreDisabled({
|
||||
endpoints: globalConfig.endpoints,
|
||||
request,
|
||||
return RouteNotFoundResponse(slug)
|
||||
} catch (error) {
|
||||
return RouteError({
|
||||
collection,
|
||||
err: error,
|
||||
req,
|
||||
})
|
||||
if (disableEndpoints) return disableEndpoints
|
||||
|
||||
const customEndpointResponse = await handleCustomEndpoints({
|
||||
endpoints: globalConfig.endpoints,
|
||||
entitySlug: `${slug1}/${slug2}`,
|
||||
payloadRequest: req,
|
||||
})
|
||||
if (customEndpointResponse) return customEndpointResponse
|
||||
|
||||
switch (slug.length) {
|
||||
case 2:
|
||||
// /globals/:slug
|
||||
res = await endpoints.global.GET.findOne({ globalConfig, req })
|
||||
break
|
||||
case 3:
|
||||
if (`doc-${slug3}` in endpoints.global.GET) {
|
||||
// /globals/:slug/access
|
||||
// /globals/:slug/versions
|
||||
res = await (endpoints.global.GET?.[`doc-${slug3}`] as GlobalRouteHandler)({
|
||||
globalConfig,
|
||||
req,
|
||||
})
|
||||
}
|
||||
break
|
||||
case 4:
|
||||
if (`doc-${slug3}-by-id` in endpoints.global.GET) {
|
||||
// /globals/:slug/versions/:id
|
||||
res = await (endpoints.global.GET?.[`doc-${slug3}-by-id`] as GlobalRouteHandlerWithID)({
|
||||
id: slug4,
|
||||
globalConfig,
|
||||
req,
|
||||
})
|
||||
}
|
||||
break
|
||||
}
|
||||
} else if (slug.length === 1 && slug1 in endpoints.root.GET) {
|
||||
res = await endpoints.root.GET[slug1]({ req })
|
||||
}
|
||||
|
||||
if (res instanceof Response) return res
|
||||
|
||||
// root routes
|
||||
const customEndpointResponse = await handleCustomEndpoints({
|
||||
endpoints: req.payload.config.endpoints,
|
||||
payloadRequest: req,
|
||||
})
|
||||
if (customEndpointResponse) return customEndpointResponse
|
||||
|
||||
return RouteNotFoundResponse(slug)
|
||||
} catch (error) {
|
||||
return RouteError({
|
||||
collection,
|
||||
err: error,
|
||||
req,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const POST =
|
||||
(config: Promise<SanitizedConfig> | SanitizedConfig) =>
|
||||
|
||||
Reference in New Issue
Block a user