Skip to content
This repository has been archived by the owner on Dec 2, 2022. It is now read-only.

Commit

Permalink
feat: add redirect page
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovyerus committed Jun 7, 2021
1 parent dc5e0ce commit 902b7f3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pages/[hash].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { GetServerSideProps } from "next";
import React from "react";

import { getRedirectByHash } from "./api/redirects/[hash]";

const RedirectPage = () => <div>You shouldn't be here 🤔</div>;

export const getServerSideProps: GetServerSideProps<{}, { hash: string }> =
async ({ params, res }) => {
const { hash } = params!;
const redirect = await getRedirectByHash(hash);

if (!redirect)
return {
notFound: true,
};
else {
res.setHeader("Cache-Control", "max-age=90");
return {
redirect: {
destination: redirect.url,
statusCode: 301,
},
};
}
};

export default RedirectPage;

0 comments on commit 902b7f3

Please sign in to comment.