Expressjs - csurf 模块在 es6 函数内使用未定义



我正在尝试在我的 es6 方法中使用 csurf 模块。我已经尝试了各种声明它以供使用的方法。不确定我在语法等方面缺少什么。

任何帮助将不胜感激。

!---错误

/

code/server/api/index.js:46var csrfProtection1 = csrf({ cookie: true }); ^

引用错误:未定义 csrf

-------类

import { Router } from 'express';
import facets from './facets';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
import csurf from 'csurf';
let csrfProtection = csrf({ cookie: true });
export default function() {
/*var csrfProtection = csrf({ cookie: true })
var parseForm = bodyParser.urlencoded({ extended: false })*/
console.log(csrfProtection); //undefined
var api = Router();
// mount the facets resource
api.use('/facets', facets);
// perhaps expose some API metadata at the root
api.get('/', (req, res) => {
    res.json({
        version : '1.0'
    });
});
return api;
}

您正在导入csurf但使用的是csrf

您似乎缺少一封信

为了避免将来出现这样的错误,您应该使用类似 http://jshint.com/

最新更新