При запросе
http://localhost:3000/api/tour/1?name=newName&price=199
Выдает
Cannot GET /api/tour/1
const express = require("express");
const handlebars = require("express-handlebars");
// const fortune = require("./lib/fortune");
const app = express();
const tours = [
{
id: 0,
name: "Река Худ",
price: 99.99
},
{
id: 1,
name: "Орегон Коуст",
price: 149.95
}
];
app.disable("x-powered-by");
app.engine("handlebars", handlebars({
defaultLayout: "main"
}));
app.set("view engine", "handlebars");
// app.use(express.static(__dirname + "/public"));
app.put("/api/tour/:id", (req, res) => {
let tour = tours.find(tour => tour.id === req.params.id);
if (tour) {
if (req.query.name) {
tour.name = req.query.name;
}
if (req.query.price) {
tour.price = req.query.price;
}
res.json(tour);
} else {
res.json({
error: "Такого тура не существует."
});
}
});
// app.get("/", (req, res) => {
// res.render("home");
// });
app.listen(3000);