Complete the code to set the deployment environment variable in Next.js.
const environment = process.env.[1];The NODE_ENV variable tells Next.js the deployment environment like development or production.
Complete the code to import the Next.js configuration file.
import [1] from 'next/config';
The function getConfig is used to access Next.js runtime configuration.
Fix the error in accessing the public runtime configuration in Next.js.
const { publicRuntimeConfig } = [1]();You must call the getConfig function to get the runtime configuration object.
Fill both blanks to correctly set environment variables in Next.js deployment.
module.exports = {
env: {
[1]: process.env.[2]
}
};Public environment variables in Next.js start with NEXT_PUBLIC_. Here, NEXT_PUBLIC_API_URL is set from process.env.API_URL.
Fill all three blanks to create a Next.js server action that uses environment variables.
export async function handler(req, res) {
const apiKey = process.env.[1];
const response = await fetch(process.env.[2] + '/data', {
headers: { 'Authorization': `Bearer ${apiKey}` }
});
const data = await response.[3]();
res.status(200).json(data);
}The server action reads the secret key API_SECRET_KEY and the base URL API_URL. It fetches data and parses it as JSON.