Node.js 如何将节点sspi与Fastfy一起使用

Node.js 如何将节点sspi与Fastfy一起使用,node.js,sspi,fastify,node-sspi,Node.js,Sspi,Fastify,Node Sspi,我想用 我试着用justify代替express。看起来它应该能工作,但它不能。它几乎相当于express代码段。我在authenticate函数中得到一个错误,告诉我传递了一个错误的参数 const fastfy=require('fastfy')({ 是的, }) 禁食路线({ 方法:“GET”, url:“/login”, onRequest:功能(req、res、next){ var nodeSSPI=require('node-sspi') var nodeSSPIObj=新nodeS

我想用

我试着用justify代替express。看起来它应该能工作,但它不能。它几乎相当于express代码段。我在authenticate函数中得到一个错误,告诉我传递了一个错误的参数

const fastfy=require('fastfy')({
是的,
})
禁食路线({
方法:“GET”,
url:“/login”,
onRequest:功能(req、res、next){
var nodeSSPI=require('node-sspi')
var nodeSSPIObj=新nodeSSPI({
retrieveGroups:true
})
nodeSSPIObj.身份验证(请求、恢复、功能(错误){
res.finished | | next()
})
},
处理程序:函数(req、res、next){
变量输出=
“你好”+
请求连接用户+
“!你的sid是”+
req.connection.userSid+
'您属于以下组:
    ' if(请求连接用户组){ for(请求连接用户组中的变量i){ out+='
  • '+req.connection.userGroups[i]+'

  • \n } } out+='
' res.send(out) } }) 快听(4000,错误=>{ 如果(错误)抛出错误 })
“fastify”:“^3.3.0”,
“节点sspi”:“^0.2.8”,

问题是类似express的中间件在fastify实例上不起作用。解决方案包括

const fastfy=require('fastfy')({logger:true})
寄存器(异步(fastfy)=>{
等待fastify.注册(需要('fastify-express'))
const nodeSSPI=require('node-sspi')
const nodeSSPIObj=新nodeSSPI()
禁食。使用((请求、回复、完成)=>{
nodeSSPIObj.authenticate(请求、回复,(错误)=>{
if(err)返回reply.code(500).send({error:err})
reply.finished | | done()
})
})
fastfy.get(“/”,(请求,回复)=>{
const{userSid,user,userGroups}=req.connection
返回reply.send({userSid,user,userGroups})
})
})
快听(3000,(错误)=>{
如果(错误)抛出错误
})

问题在于类似express的中间件在fastify实例上不起作用。解决方案包括

const fastfy=require('fastfy')({logger:true})
寄存器(异步(fastfy)=>{
等待fastify.注册(需要('fastify-express'))
const nodeSSPI=require('node-sspi')
const nodeSSPIObj=新nodeSSPI()
禁食。使用((请求、回复、完成)=>{
nodeSSPIObj.authenticate(请求、回复,(错误)=>{
if(err)返回reply.code(500).send({error:err})
reply.finished | | done()
})
})
fastfy.get(“/”,(请求,回复)=>{
const{userSid,user,userGroups}=req.connection
返回reply.send({userSid,user,userGroups})
})
})
快听(3000,(错误)=>{
如果(错误)抛出错误
})