我成功地用nextjs编写了一个中间件函数。
import type { NextRequest } from 'next/server';
import { NextResponse } from 'next/server'
export function middleware(req: NextRequest) {
const { ip, geo } = req
}
export const config = {
matcher: '/'
}
在这个中间件函数中,我得到了geo
对象和ip
字符串。在geo
对象中,它有country
、city
、latitude
、longitude
和region
字段。现在,我必须将这些数据放到我的主页组件中。
import type { NextPage, GetServerSideProps } from "next"
const Home: NextPage = () => {
return (
<div>
dfd
</div>
);
};
export default Home;
export const getServerSideProps: GetServerSideProps = async (context) => {
console.log(context);
return { props: {} }
}
如何在我的页面组件中获得像ip
、geo
这样的中间件数据。
发布于 2022-11-28 15:32:32
@Md Ali如果您在vercel部署应用程序,您将得到ip和geo。
https://stackoverflow.com/questions/74601932
复制相似问题