【发布时间】:2020-03-30 23:55:19
【问题描述】:
当我尝试引用 http://localhost: 8000/api/example 时,我在 Postman 中收到消息 Cannot GET/api/example(未找到 404)。我的目标是收到回复消息:
{
data: 'You hit example endpoint'
}
在 Postman 中我设置为 headers Content-Type: application/json
const express = require('express');
const app = express();
app.get('api/example', (req, res) => {
res.json({
data: 'You hit data endpoint'
});
});
const port = process.env.port || 8000;
app.listen(port, () => {
console.log(`connect on the port ${port}`);
});
【问题讨论】:
-
在您的路线上添加前导斜杠并将
app.get('api/example', ...)更改为app.get('/api/example', ...)
标签: javascript node.js express postman