Heyy ✨
Does anyone ever needed to access the payload Local API from another project ? If doable, how ? (it's been a week I tried EVERYTHING and about to just give up unless someone had a thought on this)
e.g. I have payload setup as an headless cms, and have an astro website wanting to query the cms in a typesafe way, but I'm not in a monorepo setup (and wasn't able to make it work anyway in this setup, maybe because I don't understand anything ¯_(ツ)_/¯).
Ultimately I looked for something to build the payload config (like we build payload types) that I could have as an npm dependency of my fronted project. (without secrets in the output of course)
So I could basically like import this payload-config, package, perhaps even build and export a wrapper around not even care about the payload dependencies and possible versions missmatch. And type the needed secret vars for a better typesafe usage.
e.g.
import { getPayload } from 'payload';
import configPromise from '@/payload.config';
interface Params {
databaseUri: string;
payloadSecret: string;
// ...
}
export default async function getLocalApi(params: Params) {
// ...
const payload = await getPayload({ config: configPromise });
// ...
return payload;
}
I know this is explained here somehow https://payloadcms.com/docs/local-api/outside-nextjs
but,
- it won't work a least in dev mode for a serverless hosted astro website if I'm right (how to exec from payload instead of node or astro ?)
- I can't really import my config from my cms project to my astro project (always having different ts config making them uncompatible, even though I'm using the default payload-website template and astro default scaffolding.)
Maybe I'm just trying to hack things, but only because I can't make what the doc says work in my headerless payload, astro frontend setup.
I'd love some help, perhaps even talking about this
Many thanks ✨


