无法使用节点&Express(Jade,MongoDB,Express,Node)进行POST

我有一个表单,用户可以select一个.xlsx文件并上传它:

p Upload New Schedule #uploadNew form(id = "form1", action="/uploadNew", method="post", enctype="multipart/form-data") input(type="file", id="control", name="XLupload") br input(type="submit" value="Upload" name="Submit") 

在我的主要app.js我有这条路线来处理它。

 var uploads = require('./routes/upload'); //Make the db accessible to various http requests app.use(function(req, res, next) { req.db = dbMain; next(); }); app.use('/', routes); app.use('/upload', uploads); 

和在我的upload.js文件中,我有以下几点:

 var xlsx = require('xlsx'); var multer = require('multer'); var upload = multer({dest: './uploads'}); var excel_upload = upload.single('XLupload'); router.get('/upload', stormpath.groupsRequired(['Enforced']), function(req, res) { res.render('upload', { title: 'Uploading Excel File' }); next(); }); router.post('/upload', excel_upload, function(req, res) { // Get the path to the uploaded Excel file var fileObject = req.file; var filePath = fileObject.path; // Get collection instance which will store the data from the newly posted schedule var dbLocal = req.db; var insertionCollection = dbLocal.collection('chip'); ..... 

但是,当我启动并在本地主机听,当我select一个文件,并尝试上传我得到错误不能POST /上传。 当我没有路线,并在主app.js文件中的一切,这不是一个问题。 我通过引入路线搞砸了什么?

这个:

 app.use('/upload', uploads); 

结合这一点:

 router.post('/upload', ...) 

声明此路线: POST /upload/upload

如果你安装一个路由器(使用app.use(PATH, router) ), PATH为该路由器处理的所有路由添加一个前缀。 您的路由器需要声明相对于该前缀的路由:

 router.post('/', ...)