Closed denolfe closed 7 months ago
This is one problem I am facing as well. One of the most awaited changes for me was the separation between the backend and frontend code from payload so that the Local API can be used à la prisma to interact with the DB.
Unfortunately, the config file still pulls in some CSS code and prevents me from using payload in simple node scripts.
@valerioleo we were hoping for the same too. No success just yet.
We want to use the localAPI from Payload 3.x in a production website while we keep the CMS interface on 2.x until it's more stable (and all the plugins, add-ons, and all the other things we tuned is ported and 3x is on final API).
To proceed with this (localAPI is super useful on nextjs side) we're trying to bootstrap payload with a lightweight Payload config with mainly primitives (collections, globals, fields). We're almost done with this and have some minor issues (hook support and some small bugs) to fix.
Perhaps that's an approach you could use?
We have some plans for this and are going to release some things in the near future which will make this all super easy - @denolfe and I will update here shortly!
Fixed.
https://github.com/payloadcms/payload-3.0-alpha-demo/commit/ec95e415c60fe9f89e998ef13e6c24da1aeb8b26
Example script can be run with pnpm standalone-script
Is possible to make it works with v2 ? Or only v3?
You can use Local API in v2, but not as a standalone since it's bundled with all the express middleware stuff.
If someone need a typesafe REST API for payload v2 they can look at payload-rest-client
Attempting to run a script that uses the Local API currently errors due to scss files being pulled in.
Example script:
Executed with
tsx
:pnpm tsx src/scripts/test.ts
Output: