这是一个创建于 2427 天前的主题,其中的信息可能已经有所发展或是发生改变。
各位前辈,我的 Node 代码收到以下报错,我实在看不懂报错的意思和应该怎样解决,求指点
if (fn.handle && fn.set) app = fn;
^
TypeError: Cannot read property 'handle' of undefined
at Function.app.use (/Users/sylvia/Documents/FE/Daily-Learning/Node/final/node_modules/express/lib/application.js:110:9)
at Object.<anonymous> (/Users/sylvia/Documents/FE/Daily-Learning/Node/final/server.js:46:8)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:140:18)
at node.js:1043:3
以下为全部代码
var express = require('express');
var expressStatic = require('express-static');
var mysql = require('mysql');
var cookieParser = require('cookie-parser');
var cookieSession = require('cookie-session');
var bodyParser = require('body-parser');
var consolidate = require('consolidate');
var expressRoute = require('express-route');
var multer = require('multer');
var multerObj = multer({dest:'./static/upload'});
var server = express();
server.listen(8080);
//1 获取前台请求数据
//get 自带
server.use(multerObj.any());
//2 获取 cookie、session
server.use(cookieParser());
(function(){
var keys=[];
for(var i=0;i<100000;i++){
keys[i]='a_' + Math.random();
}
server.use(cookieSession({
name:'sess_id',
keys:keys,
maxAge:20*60*1000 //20mins
}));
})();
//3 模版
server.engine('html',consolidate.ejs);
server.set('views','template');
server.set('view engine','html');
//4route
var r1 = express.Router();
var r2 = express.Router();
server.use('/article/',r1);
r1.get('/1.html',(req,res)=>{
res.send('我是文章').end();
});
r1.get('/2.html',(req,res)=>{
res.send('我也是文章').end();
});
server.use('/blog/',r2);
r2.get('/a.html',(req,res)=>{
res.send('我是 blog').end();
});
r2.get('/b.html',(req,res)=>{
res.send('我也是 blog').end();
});
//5default:static
server.use(expressStatic('./static/'))
2 条回复 • 2018-04-07 12:00:58 +08:00
|
|
1
Sparetire 2018-04-06 11:30:10 +08:00 via Android
server.js 46 行,估计有哪个地方没传参数导致空指针异常
|