Skip to content
Discussion options

You must be logged in to vote

You can use NEXT_PUBLIC within an env file to use different API endpoints based upon the environment.

By default, env variables are converted to strings, so they don't need quotes.

env.development
NEXT_PUBLIC_API=http://localhost:3000/api

env.production
NEXT_PUBLIC_API=https://nextjs-blog.christiankozalla.vercel.app/api

const updateColumn = async (id, column) => {
  try {
    await fetch(`${process.env.NEXT_PUBLIC_API}/posts/${id}`, {
      method: "PUT",
      headers: {
        "Content-type": "application/json; charset=UTF-8",
      },
      body: JSON.stringify({ column: column }),
    });
  } catch (error) {
    console.error(error);
  }
};

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@christiankozalla
Comment options

Answer selected by christiankozalla
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants