我可以在 get 或 post 调用中访问请求标头
fastify.get('/route1',(req,res,next)=>{
console.log(req.headers.Authorization)
...
}
我正在寻找一种将其传递给插件注册调用的方法,特别是fastify-graphql
const { graphqlFastify } = require("fastify-graphql");
fastify.register(graphqlFastify,
{
prefix: "/graphql",
graphql: {
schema: schema,
rootValue: resolvers,
context:{auth:req.headers.Authorization} <-----
}
},
err => {
if (err) {
console.log(err);
throw err;
}
}
);
有没有办法编写包装器或任何想法?