Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Local API usage

default discord avatar
kariyngva.2 years 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"

  • discord user avatar
    jarrod_not_jared
    2 years 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.2 years ago

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

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.