Skip to content
Discussion options

You must be logged in to vote

Halo! Great question - environment-specific API routes are a common challenge in Next.js projects. Let me share how our team approaches this in Next.js 15 with App Router:

Current Approach: Environment Variables (The Messy Way) ❌

What you're doing now:

// pages/api/users/route.ts (or app/api/users/route.ts)
export async function GET(request: Request) {
  if (process.env.NODE_ENV === 'development') {
    // Mock data for development
    return Response.json({ users: mockUsers });
  } else if (process.env.NODE_ENV === 'staging') {
    // Staging-specific logic
    return Response.json({ users: stagingUsers });
  } else {
    // Production logic
    return Response.json({ users: await fetchR…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by rizalulul
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