ответьте на это SO
$ git reflog show
93567ad HEAD@{0}: reset: moving to HEAD@{6}
203e84e HEAD@{1}: reset: moving to HEAD@{1}
9937a76 HEAD@{2}: reset: moving to HEAD@{2}
203e84e HEAD@{3}: checkout: moving from master to master
203e84e HEAD@{4}: reset: moving to HEAD~1
9937a76 HEAD@{5}: reset: moving to HEAD~1
d5bb59f HEAD@{6}: reset: moving to HEAD~1
9300f9d HEAD@{7}: commit: fix-bug
# said the commit to be recovered back is on 9300f9d (with commit message fix-bug)
$ git reset HEAD@{7}
У вас есть свой день назад! :)
Следуйте этой статье, чтобы разработать приложение с использованием экспресс-маршрутизатора.
https://scotch.io/tutorials/learn-to-use-the-new-router-in-expressjs-4 [ 112]
определите ваш контроллер следующим образом
exports.index = function(req, res, next) {
Contact.get(function(err, contacts) {
if (err) {
next(null,{
status: "error",
message: err
});
}
next({
status: "success",
message: "Contacts retrieved successfully",
data: contacts
},null);
});
};
Определите основной файл приложения следующим образом
var contactController = require('./contactController');
var router = express.Router();
// apply the routes to our application
// route middleware that will happen on every request
router.use(function(req, res, next) {
// continue doing what we were doing and go to the route
next();
});
// about page route (http://localhost:8080/about)
router.get('/contacts', function(req, res) {
//here you can call your controller js method
contactController.index(req,res, function(data, err){
//change anything you want here and set into res.
if(err){
//change status and data
}
else{
//change status and data
}
})
});
Не завершайте цикл запрос-ответ в контроллере, просто верните результат из контроллера, а не заканчивайте цикл.
const httperror = require('http-errors');
exports.index = async function(parameter) {
Contact.get(function(err, contacts) {
if (err) {
throw new httperror(400, "Error occured!");
}
return {
status: "success",
message: "Contacts retrieved successfully",
data: contacts
}
});
};
Запрос должен начинаться с маршрута, а ответ должен отправляться с маршрута.
const contactController = require('./contactController');
router.get('/contacts', function (req, res, next) {
contactController.index()
.then(result => {
res.json(result)
}).catch((error) => {
res.status(200).json({"Error":"Returned success code 200 even though error
occured"});
})
});