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`
-
-
-
-
-
404
-
-
-
-
-
-
-
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);