Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3686

How to resolve empty response from route handler when RSC component?

$
0
0

route handler is as follows:API Path: http://localhost:3000/merchants/{merchatnSlug}/products/api

import base_url from "@/app/_util/StrapiConfig";import { NextResponse } from "next/server";export async function GET(request, context) {    console.log("route handler called!, revalidate", context);    const slug = context?.params?.merchantSlug ?? process.env.NEXT_PUBLIC_MERCHANT_NAME;    const response = await fetch(base_url +        `/products?populate=*&attributes[merchant][data][attributes][slug]=${slug}`, {        headers: {            'Authorization': `Bearer ${process.env.NEXT_PUBLIC_STRAPI_TOKEN}`,        },    });        const data = await response.json();    return NextResponse.json(data);}

RSC (React Server component):

import ProductSection from '@/app/_components/ProductSection';import React from 'react'// import { unstable_noStore as noStore } from 'next/cache';import base_url from '@/app/_util/StrapiConfig';const Products = async ({ params }) => {  const merchantSlug = params?.merchantSlug || process.env.NEXT_PUBLIC_MERCHANT_NAME;  let products = await fetch(process.env.NEXT_PUBLIC_HOST_URL + `/merchants/${merchantSlug}/products/api`);  console.log("products in page.js", JSON.stringify(products, null, 2));  return (<div className='mt-10 sm:px-10 md:px-20'><ProductSection productList={products} /></div>  )}export default Products;

When i call route handler from postman it works fine but to RSC Component it returns an empty response.

Screenshot of API called route handler is working as expected!

logs from next.js server

✓ Compiled /merchants/[merchantSlug]/products/api in 67ms (359 modules)route handler called!, revalidate { params: { merchantSlug: 'truedesignconcept' } } GET /merchants/truedesignconcept/products/api 200 in 901msproducts in page.js {}⨯ Error: Only plain objects, and a few built-ins, can be passed to Client Components from Server Components. Classes or null prototypes are not supported.

Thanks in advance for helping me!

Response in RSC should be same as API call to route handler from Thunder Client(postman).


Viewing all articles
Browse latest Browse all 3686

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>