diff --git a/server.js b/server.js index c62c12c..6fe573f 100644 --- a/server.js +++ b/server.js @@ -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) { diff --git a/src/storage.js b/src/storage.js index 6be8dc0..a6cde6e 100644 --- a/src/storage.js +++ b/src/storage.js @@ -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]