500 TypeError: Cannot read property 'connect.sid' of undefined
1:在写passport验证测试用例时,发现有几个引用中间件顺序的错误,检查发现,passport验证写的是session,在传错误信息的时候req.flash调用也需要用到session中间件,否则会报错:

我先引用 app.use express.session({secret: 'keyboard'})
2:引用后,运行代码,又报错:

由于会话是使用cookie实现的,因此还得引用cookie中间件
app.use express.cookieParser()
cookie一定要写到session中间件的前面,原因:
Middleware order matter in Express, as they are executed in the order you defined them. In your case, the cookieParser middleware adds some information that is used by the session middleware.
You can check connect's documentation:
Session data is not saved in the cookie itself, however cookies are used, so we must use the cookieParser() middleware before session().
3: 发现了个很妖的情况,在form窗里里submit后,input输入框的数据居然没有带到body里,每次body都是空的,检查出来发现urlencoded中间件居然被我屏蔽掉了,好火大,
app.use express.json()
app.use express.urlencoded()
其实 bodyParser() 支持 JSON, urlencoded和multipart requests的请求体解析中间件。 这个中间件是json(), urlencoded(),和multipart() 这几个中间件的简单封装
app.use(express.bodyParser()); // 等同于:
app.use(express.json());
app.use(express.urlencoded());
app.use(express.multipart());
那为什么不用express.bodyParser来的方便????????当我使用bodyParser()替换时,运行警告:
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
原来connect移除了所有中间件,connect.multipart()更是访问不到了,express版本: "version": "3.5.1", 难怪用express自动建项目的时候直接使用的app.use express.json();app.use express.urlencoded()
其他人的解释:connect 发布了 3.0, 移除了所有中间件。express 发布了 4.0,移除了 connect 的依赖。express 老版本引用了 connect 2.x,所以会有这个提示。
express.multipart()中间件用于文件上传,如果没有文件上传建议就别用了
在做一个文件上传的时候,需要用到req.files这个属性,如果不用app.use(express.bodyParser())这个代码就会报错了,这个时候是不是只能回到express的旧版本呢????
500 TypeError: Cannot read property 'connect.sid' of undefined的更多相关文章
- 微信小程序开发——使用回调函数出现异常:TypeError: Cannot read property 'setData' of undefined
关键技术点: 作用域问题——回调函数中的作用域已经脱离了调用函数了,因此需要在回调函数外边把this赋给一个新的变量才可以了. 业务需求: 微信小程序开发,业务逻辑需要,需要把获取手机号码的业务逻辑作 ...
- vue.common.js?e881:433 TypeError: Cannot read property 'nodeName' of undefined
我觉得吧,是这么个原因,就是响应式要找这个node改它的内容,没找着,就报错了. 用computed监控vuex的state属性,绑定到页面上,如果这个属性改了,因为响应式,那么就要更改页面,如果页面 ...
- Uncaught TypeError: Cannot read property 'msie' of undefined
因为图方便,抄了别人写的一个jquerry插件,运行时“var pos = ($.browser.msie && parseInt($.browser.version) <= 6 ...
- Uncaught TypeError: Cannot read property 'insertAdjacentHTML' of null
在开发Ext 项目中如果遇到 Uncaught TypeError: Cannot read property 'insertAdjacentHTML' of null 这个错误,检查下renderT ...
- easyui使用时出现这个Uncaught TypeError: Cannot read property 'combo' of undefined
easyui使用时出现这个Uncaught TypeError: Cannot read property 'nodeName' of undefined 最后检查发现是必须给select一个id,光 ...
- Uncaught TypeError: Cannot set property 'innerHTML' of null
学习Chrome插件时,要在弹出页面中显示当前时间,结果怎样也显示不出来 看了 http://www.cnblogs.com/mfryf/p/3701801.html 这篇文章后感悟颇深 通过调试发现 ...
- Uncaught TypeError: Cannot read property 'call' of undefined jquery.validate.min.js:28
最近在做表单验证时,,自己写的addMethod 方法总是不起作用.折腾了将近一天. 报告的错误,如下面的 Uncaught TypeError: Cannot read property 'call ...
- reactjs Uncaught TypeError: Cannot read property 'location' of undefined
reactjs Uncaught TypeError: Cannot read property 'location' of undefined reactjs 路由配置 怎么跳转 不成功 国内搜索引 ...
- index.js:13 Uncaught TypeError: Cannot read property 'split' of undefined
使用 webpack 编译 Vue 项目时出现报错: index.js:13 Uncaught TypeError: Cannot read property 'split' of undefined ...
随机推荐
- JQuery 选中Radio
<tr> <td> <input type="radio" name="rdb" value="启用" che ...
- How to build a GUI in ROS with Qt / C++
p { margin-bottom: 0.1in; direction: ltr; line-height: 120%; text-align: left; widows: 2; orphans: 2 ...
- Spark.ML之PipeLine学习笔记
地址: http://spark.apache.org/docs/2.0.0/ml-pipeline.html Spark PipeLine 是基于DataFrames的高层的API,可以方便用户 ...
- LAMP配置
参考资料: 1. http://www.cnblogs.com/zhuyp1015/p/3561470.html ↂ Apache服务器: 安装Apache: sudo apt-get install ...
- phpcms 在后台增加了一个模型的话,在数据库中就会相应的增加数据库表
在phpcms后台管理系统中,我们如果增加一个新的模型的话,例如名为:测试模型,英文名:test 在添加完成后,我们在数据库中发现增加了两个数据表:v9_test,v9_test_data;
- MyEclipse启动Tomcat服务器时老是跳到Debug调试上
window->preferences->Myeclipse->Servers->Tomcat 然后找到你的相应的Tomcat服务器的版本, 选中然后展开其下面的子菜单会发现有 ...
- Python学习笔记day5
模块 1.自定义模块 自定义模块就是在当前目录下创建__init__.py这个空文件,这样外面的程序才能识别此目录为模块包并导入 上图中libs目录下有__init__.py文件,index.py程序 ...
- ZOJ-2364 Data Transmission 分层图阻塞流 Dinic+贪心预流
题意:给定一个分层图,即只能够在相邻层次之间流动,给定了各个顶点的层次.要求输出一个阻塞流. 分析:该题直接Dinic求最大流TLE了,网上说采用Isap也TLE,而最大流中的最高标号预流推进(HLP ...
- iOS - AutoLayout
前言 NS_CLASS_AVAILABLE_IOS(6_0) @interface NSLayoutConstraint : NSObject @available(iOS 6.0, *) publi ...
- Win7_提高性能
1. 设置成经典主题:桌面->右键->个性化->经典主题 2. 计算机->右键->属性->高级系统设置 ==> 系统属性->高级->性能-> ...