From 77c061bc0b8aecce7311ce820b3401c95797a589 Mon Sep 17 00:00:00 2001 From: jackyzha0 Date: Sun, 11 Apr 2021 11:40:44 -0700 Subject: working raw paste fetch --- frontend/src/pages/raw/[hash].js | 24 ++++++++++++++++++++++++ frontend/src/pages/raw/index.js | 14 -------------- 2 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 frontend/src/pages/raw/[hash].js delete mode 100644 frontend/src/pages/raw/index.js (limited to 'frontend/src/pages/raw') diff --git a/frontend/src/pages/raw/[hash].js b/frontend/src/pages/raw/[hash].js new file mode 100644 index 0000000..d0a66a7 --- /dev/null +++ b/frontend/src/pages/raw/[hash].js @@ -0,0 +1,24 @@ +import React from 'react'; +import resolvePaste from "../../http/useFetchPaste"; +import {CodeLike} from "../../components/Common/mixins"; +import styled from 'styled-components' + +const RawText = styled.pre` + ${CodeLike} + padding: 0 1em; +` + +export async function getServerSideProps(ctx) { + const data = await resolvePaste(ctx.params.hash) + + // Pass data to the page via props + return { props: { ...data } } +} + +const Raw = ({error, data}) => { + return + {data?.content || error} + +} + +export default Raw \ No newline at end of file diff --git a/frontend/src/pages/raw/index.js b/frontend/src/pages/raw/index.js deleted file mode 100644 index 86db3d4..0000000 --- a/frontend/src/pages/raw/index.js +++ /dev/null @@ -1,14 +0,0 @@ -import React from 'react'; -import useFetchPaste from "../../http/useFetchPaste"; -import { useRouter } from 'next/router' - - -export default (req, res) => { - const router = useRouter() - const { hash } = router.query - const { err, result } = useFetchPaste(hash) - res.statusCode = 200 - res.json({ - text: 'Hello World! This is the Next.js starter kit :D', - }) -} \ No newline at end of file -- cgit v1.2.3