【问题标题】:Express js, app.post not receiving connectionExpress js,app.post没有收到连接
【发布时间】:2016-11-04 10:29:12
【问题描述】:

我正在尝试使用 NodeJS 创建一个应用程序,但偶然发现了一个问题。我使用 Postman 来检查 post 请求,但服务器从未进入该函数。 GET 请求工作正常。 我该怎么做才能解决这个问题?

部分代码:

app.use(reloadify);
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(session({
    secret: 'secret',
    resave: false}));


app.locals.basedir = "static";
app.use(express.static(__dirname + "/static/"));

app.post('/api/upload', function(req, res) {
    console.log('received');
    res.send(req.body);
});

app.listen(80, function(){
    console.log("Listening");
    console.log(__dirname);
});

编辑: 似乎 reloadify 模块阻止了发布请求。评论这一点使其工作。将问题改为如何使它们都起作用。

编辑 2: 这是 reloadify 中的一个错误,我创建了一个新分支并修复了它。 感谢您的帮助。

【问题讨论】:

  • 你能把你的整个代码贴在这里吗?
  • 什么是重载?它是你的本地模块吗?
  • @AlongkornChetasumon reloadify 是一个在静态文件更改时刷新浏览器的模块。 github.com/alessioalex/reloadify

标签: node.js express reactjs


【解决方案1】:

Reloadify 有一个错误,它只允许 HTTP: GET 和 HEAD 方法通过 express 中间件。对于 Express js,editing the middleware function to go to the next layer fixes it

我希望我使用的是正确的术语。

【讨论】:

    猜你喜欢
    • 2015-03-04
    • 2021-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多