This commit is contained in:
ポール ウェッブ 2019-01-18 12:15:17 -06:00
parent 6db9abc521
commit d949093e53
3 changed files with 6 additions and 50 deletions

View file

@ -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}`);

View file

@ -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`
<article class="page" itemtype="http://schema.org/BlogPosting">
<header class="page__header">
<div class="page__header-wrap">
<div class="inner-wrap">
<h1 class="page__header__title" itemprop="name headline">404</h1>
</div>
</div>
</header>
<section class="page__content page__markup" itemprop="articleBody">
<div class="inner-wrap">
<p>Redirecting you to <strong>${redirectUrl}</strong></p>
</div>
</section>
</article>
<script>
setTimeout(() => {
window.location.href = "${redirectUrl}";
}, 2000);
</script>
`;
}
return page404();
};

View file

@ -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);