访问localhost:5000时index.js无法获取/

时间:2018-07-01 00:21:18

标签: javascript node.js

const FatSecret = require('./fatsecret');
const fatAPI = new FatSecret('50cee42503b74b4693e3dc6fccff8725','2755697297a84ac5a702461b166e71f6');
// Express webhook
const express = require('express');
const app = express();
const PORT = process.env.PORT || 5000
app.use( express.json() );
app.post('/', (req, res) => processWebhook( req, res ));
app.listen(PORT, () => console.log(`Listening on port ${ PORT }`));
var processWebhook = function( request, response ){
if (request.body.result) {
processV1Request(request, response);
} else if (request.body.queryResult) {
processV2Request(request, response);
} else {
console.log('Invalid Request');
return response.status(400).end('Invalid Webhook Request (expecting v1 or v2 webhook request)');
  }
}

我正在尝试访问localhost:5000,但我收到错误,无法获取/ 我正在使用here

中的API

1 个答案:

答案 0 :(得分:1)

伙计,如果您所说的是正确的,则您正在尝试获取该端点,但是您的路线是POST:

app.post('/', (req, res) => processWebhook( req, res ));

尝试:

app.get('/', (req, res) => processWebhook( req, res ));

尽管如此,我认为您确实想进行POST(因为您需要尸体)。如果您正在测试应用程序的状态,请确保您正在发布!