diff options
| author | jackyzha0 <[email protected]> | 2021-04-11 11:40:44 -0700 |
|---|---|---|
| committer | jackyzha0 <[email protected]> | 2021-04-11 11:40:44 -0700 |
| commit | 77c061bc0b8aecce7311ce820b3401c95797a589 (patch) | |
| tree | 6ec62987330f74b4dfca95dfaaa8cd5c723d1b58 /frontend/src/pages/raw | |
| parent | safely remove style.css (diff) | |
| download | ctrl-v-77c061bc0b8aecce7311ce820b3401c95797a589.tar.xz ctrl-v-77c061bc0b8aecce7311ce820b3401c95797a589.zip | |
working raw paste fetch
Diffstat (limited to 'frontend/src/pages/raw')
| -rw-r--r-- | frontend/src/pages/raw/[hash].js | 24 | ||||
| -rw-r--r-- | frontend/src/pages/raw/index.js | 14 |
2 files changed, 24 insertions, 14 deletions
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 <RawText> + {data?.content || error} + </RawText> +} + +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 |