Local API usage

default discord avatar
kariyngva
6 months ago
2

Is the Local API not intended for use by FE applications?


Or am I just holding it wrong?



The listed common use cases don't include it but the "tip" on the documentation page says

The Local API is incredibly powerful when used with server-side rendering app frameworks like NextJS.



I'm running the following inside of the

getServerSideProps

of a page:


await payload.init({
    secret: process.env.PAYLOAD_SECRET ?? '',
    mongoURL: process.env.MONGODB_URI ?? '',
    local: true,
  });

And I'm getting a

cannot find Payload config.

Edit: my payload code and fe/next code are in separate repos so the config isn't "near by"

  • default discord avatar
    Jarrod
    6 months ago

    You will need the config in order to boot up payload. So if you

    really

    wanted to use the local api you would have to copy it over. The docs are mainly referring to scenarios where the FE/BE are colocated.



    In your case though, I would probably save myself the hassle of copying configs, and make fetch requests to your hosted payload api endpoints.

  • default discord avatar
    kariyngva
    6 months ago

    Yeah it makes sense, kinda figured I'd need to provide the collections/globals at the very least. Thanks 😄

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.