How to set env sandbox through nextJS

Hi there,
Currently, I am trying to build a local app with nextJS,
in .env.local file, I set as below

X-Environment="my-sandbox"

but I get a 404 response, it seems the env variable was not set correctly and it did not detect my sandbox.

Do you know where I might be wrong?
refer to NextJS doc: Basic Features: Environment Variables | Next.js

Hello @jeff.f.chen

To do so you can build a site client as the following documentation: https://www.datocms.com/docs/content-management-api/using-the-nodejs-clients#specifying-a-sandbox-environment
If you don’t want to hard code it directly on the client initialisation you can substitute the hardcoded string by the value of the .env file variable

Hi @m.finamor,
I don’t need to create a client here since I don’t do any CRUD on DATO,
The only thing I will do is to tell the server which sandbox I am using and show the content of that sandbox on my webpage.

So don’t know if there’s other solution for it?

Thanks for your answer!

@jeff.f.chen to do that you are interacting with our API in some way, if you aren’t using the REST API you are probably using our graphQL API then, and to specify the environment there, you can just specify this header on your request: Content Delivery API - API Endpoint - DatoCMS Docs

If not, let me know how you are fetching the content from Dato to show on your page

Hi @m.finamor
Yes I fixed with adding X-Environment into the heading, thanks a lot!

1 Like