Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NextJS Adapter Not Picking up App Router Route Handlers #194

Open
jherr opened this issue Dec 10, 2023 · 1 comment
Open

NextJS Adapter Not Picking up App Router Route Handlers #194

jherr opened this issue Dec 10, 2023 · 1 comment

Comments

@jherr
Copy link

jherr commented Dec 10, 2023

I have a fetch in App Router based API route using router and the fetch is not being picked up by the nextjs adapter. Other fetchs are, either in RSCs or in the client, so the adapter is configured properly.

I notice the example nextjs application doesn't have API routes. Might help to add those to make sure that calls made through those get collected properly.

@kgpax
Copy link
Member

kgpax commented Feb 26, 2024

Have also reproduced this.

For example, the below implementation does show the trace in Envy.

import axios from 'axios';
import { NextResponse } from 'next/server';

const SWAPI_URL = 'https://swapi.dev/api/people/1';

export async function GET() {
  const { data } = await axios.get(SWAPI_URL); // ✅ request shows in Envy
  return NextResponse.json(data);
}

However, change from using axios to using fetch and Envy doesn't see the request:

import { NextResponse } from 'next/server';

const SWAPI_URL = 'https://swapi.dev/api/people/1';

export async function GET() {
  const resp = await fetch(SWAPI_URL); // ❌ request doesn't show in Envy
  const data = await resp.json();
  return NextResponse.json(data);
}

My suspicion is that we need to ensure that the @envyjs/nextjs adapter patches the fetch operation for the server just like it does for the client in the @envyjs/web adapter.

I'll see if some progress can be made on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants