准备运行一个程序,发现 connect一直报错
├─┬ [email protected]
var connect = require('connect');
var app = connect();
app.use('/public', connect.static(__dirname + '/public', {maxAge: 3600000 * 24 * 30}));
return;
----------------------------------错误---------------------
app.use('/public', connect.static(__dirname + '/public', {maxAge: 3600000 * 24 * 30}));
^
TypeError: Object function createServer() {
function app(req, res, next){ app.handle(req, res, next); }
merge(app, proto);
merge(app, EventEmitter.prototype);
app.route = '/';
app.stack = [];
return app;
} has no method 'static'
at Object.<anonymous> (/root/node-v0.10.32/mysql-test.js:15:23)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
3 回复
百度太无力了,google找了一下还算有人知道。 http://stackoverflow.com/questions/24336994/nodejs-connect-usage-of-built-in-modules-method-not-found 但怎么修改这个,要看一下新方法,哪位经验能将上面代码用新写法怎么替换写个例子就好了 。这个问题太坑了
connect 3.x把中间件都分离出去了。static方法变成serve-static模块。 http://stackoverflow.com/questions/24346161/nodejs-connect-cannot-find-static
var connect = require('connect');
var serveStatic = require('serve-static')
var app = connect();
app.use('/public',serveStatic(dirname + '/public', {maxAge: 3600000 24 30}));