Browse Source

deprecated link resolution crash caught

master
Christian Müller 10 years ago
parent
commit
929ab14a21
  1. 5
      server.js
  2. 2
      src/storage.js

5
server.js

@ -53,9 +53,8 @@ app.post('/note', function (req, res) { @@ -53,9 +53,8 @@ app.post('/note', function (req, res) {
});
app.get("/:year/:month/:day/:title", function (req, res) {
var P = req.params;
storage.getNoteId(P.year + "/" + P.month + "/" + P.day + "/" + P.title)
.then(id => res.redirect("/" + id));
var P = req.params, url = P.year + "/" + P.month + "/" + P.day + "/" + P.title;
storage.getNoteId(url).then(note => note ? res.redirect("/" + id) : notFound(res));
});
app.get(/\/([a-z0-9]+\/edit)/, function (req, res) {

2
src/storage.js

@ -28,7 +28,7 @@ module.exports.getNoteId = deprecatedId => { @@ -28,7 +28,7 @@ module.exports.getNoteId = deprecatedId => {
console.log("resolving deprecated Id", deprecatedId);
return Note.findOne({
where: { deprecatedId: deprecatedId }
}).then(note => note.id);
});
}
var generateId = () => [1, 1, 1, 1, 1]

Loading…
Cancel
Save