node.js mongodb express - 无法POST /

时间:2014-08-19 11:54:04

标签: node.js mongodb express

var express = require('express');
var mongoUtils = require('./mongooseData.js')

var app = express();

app.get('/businesses' , mongoUtils.findAllBusinesses);
app.post('/newBusiness' , mongoUtils.enterNewBusiness);

app.listen(3000);

这是服务器,我不知道为什么但是GET正在工作,但POST不是,

我尝试使用commandprompt(curl -X POST localhost ... -d ...) 并使用chrome扩展REST

我仍然无法发布POST /

来自节点服务器的回复是“OK”并打印到控制台

1 个答案:

答案 0 :(得分:1)

问题可能在于您没有正确处理响应。

我试过这个并且工作了(快递4.8.5):

var express = require('express');
var log = function(req, res, next) {
    console.log('Logging');
    res.end();
};

var app = express();

app.get('/businesses' , log);
app.post('/newBusiness' , log);

app.listen(3000);

得到了:

$ curl -i localhost:3000/businesses
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 0
ETag: W/"0-0"
Date: Tue, 19 Aug 2014 12:45:14 GMT
Connection: keep-alive

$ curl -X POST -i localhost:3000/newBusiness
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 0
Date: Tue, 19 Aug 2014 12:45:17 GMT
Connection: keep-alive

确保您拥有res.sendres.endres.status或类似内容。