【发布时间】:2021-02-12 23:22:46
【问题描述】:
我需要在这个函数上添加一些node js中间件
export async function getServerSideProps(ctx) {
console.log('coo',cookieParser(ctx.req.headers.cookie));
console.log('headers', ctx.req.headers.cookie);
const res = await fetch('http://localhost:1337/publics')
const data = await res.json()
const theData = data[ctx.query.id - 1]
return {
props: {data: theData},
}
}
我需要使用cookie解析器中间件,这里有没有添加中间件,如果没有,我如何从cookie中获取信息
【问题讨论】:
-
默认情况下,您已经可以访问
getServerSideProps中的req.cookies。