reactjs - How to Retrieve Client IP and User Agent in a Next.js Server Component? - Stack Overflow

I have a simple Next.js app with the following server component:import { headers } from 'nexthea

I have a simple Next.js app with the following server component:

import { headers } from 'next/headers';

export default async function Page() {
  const headersList = await headers();
  console.log(headersList);
  return <h1>Hello, Dashboard Page!</h1>;
}

According to the Next.js documentation, I should be able to retrieve headers, including the client's IP address and User-Agent, by using headers() in an asynchronous server page. However, when I log headersList, it only returns an empty object.

How can I correctly retrieve the client’s IP address and User-Agent in a Next.js server component? Is there something I am missing in the configuration, or is this approach incorrect?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742332268a4423954.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信