From 0afc56d32e585a47ca5f9f6697db67b887c271cf Mon Sep 17 00:00:00 2001 From: Damillora Date: Sat, 28 Sep 2019 18:00:59 +0700 Subject: [PATCH] Add error pages and handling --- layouts/error.vue | 27 +++++++++++++++++++++++++++ middleware/shorten.js | 5 +++-- pages/_.vue | 6 +++++- 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 layouts/error.vue diff --git a/layouts/error.vue b/layouts/error.vue new file mode 100644 index 0000000..0304036 --- /dev/null +++ b/layouts/error.vue @@ -0,0 +1,27 @@ + + + + + diff --git a/middleware/shorten.js b/middleware/shorten.js index 7129bf9..46a5262 100644 --- a/middleware/shorten.js +++ b/middleware/shorten.js @@ -4,9 +4,10 @@ import { tall } from 'tall'; export default function (context) { return tall(process.env.SHORTENER_BASE+context.route.path).then(function(unshortenedUrl) { if(unshortenedUrl == process.env.SHORTENER_BASE) { - return; + context.error({ statusCode: 404, message: "The page cannot be found"}); + } else { + context.redirect(unshortenedUrl); } - context.redirect(unshortenedUrl); }); // context.redirect("https://nanao.moe"); } diff --git a/pages/_.vue b/pages/_.vue index 066ee6f..e648f3e 100644 --- a/pages/_.vue +++ b/pages/_.vue @@ -1,6 +1,10 @@