如何在meteor应用程序中正确configuration节点中间件
我已经在我的meteor应用程序中安装了multer中间件:
{ "multer": "0.1.8" }
我有meteorhack:npm也安装了
现在,我正在尝试这样configurationmiddlware:
var multer = Meteor.npmRequire('multer'); Meteor.app .use(multer({ dest: './uploads/', rename: function (fieldname, filename) { return filename+Date.now(); }, onFileUploadStart: function (file) { console.log(file.originalname + ' is starting ...'); }, onFileUploadComplete: function (file) { console.log(file.fieldname + ' uploaded to ' + file.path); var fileName = file.name; var done=true; } }));
当只有第一行时,我没有任何问题。
但是,当我试图实际configuration中间件时,出现以下错误:
W20150609-13:51:29.641(-5)? (STDERR) W20150609-13:51:29.641(-5)? (STDERR) /home/eugene/.meteor/packages/meteor-tool/.1.1.3.4sddkj++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245 W20150609-13:51:29.641(-5)? (STDERR) throw(ex); W20150609-13:51:29.641(-5)? (STDERR) ^ W20150609-13:51:29.644(-5)? (STDERR) TypeError: Cannot call method 'use' of undefined W20150609-13:51:29.644(-5)? (STDERR) at app/server/startup/loadMulter.js:4:6 W20150609-13:51:29.644(-5)? (STDERR) at app/server/startup/loadMulter.js:18:3 W20150609-13:51:29.644(-5)? (STDERR) at /home/eugene/dev/meteor/socially/.meteor/local/build/programs/server/boot.js:222:10 W20150609-13:51:29.644(-5)? (STDERR) at Array.forEach (native) W20150609-13:51:29.644(-5)? (STDERR) at Function._.each._.forEach (/home/eugene/.meteor/packages/meteor-tool/.1.1.3.4sddkj++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11) W20150609-13:51:29.644(-5)? (STDERR) at /home/eugene/dev/meteor/socially/.meteor/local/build/programs/server/boot.js:117:5
所以看起来,Meteor对象没有名为“app”的属性。
在那种情况下,完成这个的正确语法是什么?
meteor使用connect
来处理服务器端路由和中间件。
webapp
包暴露了一个WebApp
对象,它具有一个connectHandlers
属性,您可以在其中添加自己的中间件。
WebApp.connectHandlers.use(multer({ dest: './uploads/', [...] }));