我有一个CRUD应用程序,您可以在其中创建版本。 用户可以添加版本(版本有版本和说明) 这可以通过一个按钮和一些字段来完成,您可以在其中输入详细信息
<button (click)="addRelease(version.value, description.value)" [disabled]="angForm.pristine || angForm.invalid" class="btn btn-primary">Add</button>
我的addRelease函数:
addRelease(version, description) {
this.releaseservice.addRelease(version, description);
}
我的服务中的addRelease函数:
addRelease(version,description) {
const uri = 'http://localhost:4000/releases/add';
const obj = {
version: version,
description: description
};
this
.http
.post(uri, obj)
.subscribe(res =>
console.log('Done'));
}
然后在我的releaseRoutes.js
中 releaseRoutes.route('/releases/add').post(function (req, res) {
var release = new Release(req.body);
release.save()
.then(item => {
res.status(200).json({'release': 'release added successfully'});
})
.catch(err => {
res.status(400).send("unable to save to database");
});
});
server.js:
releaseRoutes = require('./expressRoutes/releaseRoutes')
const app = express();
app.use('/releases', releaseRoutes);
省略了一些代码以便于阅读。
当我尝试创建新版本时 它给出了404错误
POST http://localhost:4000/releases/add 404 (Not Found)
core.js:1449 ERROR HttpErrorResponse {headers: HttpHeaders, status: 404,statusText: "Not Found", url: "http://localhost:4000/releases/add", ok: false, …}
我是新手,需要一些解决此错误的帮助,已经坚持了几天
答案 0 :(得分:1)
您已在/releases
app.use('/releases', releaseRoutes);
的路线
将releaseRoutes.route('/releases/add')
更改为releaseRoutes.route('/add')