From d949093e5332ff4caf0c4e9b92483eb353b5da4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9D=E3=83=BC=E3=83=AB=20=E3=82=A6=E3=82=A7=E3=83=83?= =?UTF-8?q?=E3=83=96?= Date: Fri, 18 Jan 2019 12:15:17 -0600 Subject: [PATCH] Closes #208 --- app/index.js | 4 ++++ app/modules/redirect-404.js | 48 ------------------------------------- app/views/redirect.js | 4 ++-- 3 files changed, 6 insertions(+), 50 deletions(-) delete mode 100644 app/modules/redirect-404.js diff --git a/app/index.js b/app/index.js index 09c7076..24ec78e 100755 --- a/app/index.js +++ b/app/index.js @@ -17,6 +17,7 @@ import websockets from "@inc/fastify-ws"; import handleSocketMessages from "./sockets"; import messageSlack from "./helpers/slack"; +import redirects from "./data/redirects.json"; const server = fastify({ logger: { @@ -46,6 +47,9 @@ server app: require("./client") }) .addHook("preHandler", (request, reply, next) => { + if (redirects[request.raw.originalUrl]) + reply.redirect(301, redirects[request.raw.originalUrl]); + if (process.env.NODE_ENV !== "development") { if (request.headers["x-forwarded-proto"] !== "https") reply.redirect(302, `https://${request.raw.hostname}${request.raw.originalUrl}`); diff --git a/app/modules/redirect-404.js b/app/modules/redirect-404.js deleted file mode 100644 index c699305..0000000 --- a/app/modules/redirect-404.js +++ /dev/null @@ -1,48 +0,0 @@ -"use strict"; - - - -// I M P O R T - -import html from "choo/html"; - -// U T I L S - -import page404 from "../views/404"; -import redirects from "../data/redirects.json"; - - - -// E X P O R T - -export default state => { - const redirectUrl = redirects[state.href]; - - if (redirectUrl) { - return html` -
- - -
-
-

Redirecting you to ${redirectUrl}

-
-
-
- - - `; - } - - return page404(); -}; diff --git a/app/views/redirect.js b/app/views/redirect.js index 57465cc..0e6289a 100644 --- a/app/views/redirect.js +++ b/app/views/redirect.js @@ -12,7 +12,7 @@ import raw from "choo/html/raw"; // U T I L S import markdown from "../components/markdown"; -import redirect404 from "../modules/redirect-404"; +import page404 from "./404"; @@ -23,7 +23,7 @@ export default (state, emit) => { // eslint-disable-line const path = `./documents/${partialPath}.md`; if (!fs.existsSync(path)) - return redirect404(state); + return page404(); const markdownFile = fs.readFileSync(path, "utf-8"); const markdownFileDetails = fm(markdownFile);