我收到此錯誤:

服務器.ts
import * as express from 'express';
import {Application} from "express";
import * as fs from 'fs';
import * as https from 'https';
import {retrieveUserId} from './user-middleware-extraction';
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const app: Application = express();
app.use(cookieParser());
app.use(retrieveUserId);
app.use(bodyParser.json());
` 用戶中間件提取.ts
import { NextFunction,Request,Response } from "express";
import { decodeToken } from "./security.utils";
export function retrieveUserId(res:Response,req:Request,next:NextFunction) {
const jwt = req.cookies['SESSIONID'] // retrieving the jwtoken
if(jwt) {
handleSession(jwt, req)
.then(()=>
next())
.catch(err=>
{
console.log(err);
next()
})
}
}
async function handleSession(jwt, req) {
try {
req['userId'] = payload.sub//request contain the id
var payload = await decodeToken(jwt)//payload of the jwt
}
catch(err) {
console.log("error is", err)
}
}
在將中間件分配給 server.ts 時,會彈出此錯誤。不知道是什么導致了這種情況發生。
是中間件功能的問題嗎?
uj5u.com熱心網友回復:
對不起這是我的錯。似乎您只需要交換 req 和 res 函式引數即可獲得匹配的型別。
路徑引數的順序應該是:(req, res, next). 您切換了請求和回應引數。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/526313.html
標籤:节点.js有角度的表示
