Leo 3 lat temu
rodzic
commit
fd39e5ad70
3 zmienionych plików z 6 dodań i 3 usunięć
  1. 2 1
      pages/_app.tsx
  2. 2 1
      pages/index.tsx
  3. 2 1
      pages/novels/[genre].tsx

+ 2 - 1
pages/_app.tsx

@@ -12,6 +12,7 @@ import Layout from "../components/common/Layout";
 import "../styles/globals.scss";
 import { pageview } from "../libs/gtag";
 import { GA_TRACKING_ID } from "../libs/config";
+import { get } from "../utils/http";
 
 export type NextPageWithLayout<P = {}, IP = P> = NextPage<P, IP> & {
   getLayout?: (page: ReactElement) => ReactNode;
@@ -67,7 +68,7 @@ const MyApp = ({ Component, pageProps }: AppPropsWithLayout) => {
 MyApp.getInitialProps = async function (context: AppContext) {
   App.getInitialProps(context);
 
-  const { data } = await fetch("/api/genre/list").then((res) => res.json());
+  const { data } = await get("/api/genre/list");
 
   return {
     pageProps: { genre: data },

+ 2 - 1
pages/index.tsx

@@ -1,6 +1,7 @@
 import useGet from "../utils/hooks/useGet";
 import type { ListItem } from "../types/http";
 import NovelItem from "../components/NovelItem";
+import { get } from "../utils/http";
 
 const Home = () => {
   const { data } = useGet<ListItem[]>("/api/list");
@@ -23,7 +24,7 @@ const Home = () => {
 };
 
 export async function getServerSideProps() {
-  const data = await fetch(`/api/list`).then((res) => res.json());
+  const data = await get(`/api/list`);
 
   return {
     props: {

+ 2 - 1
pages/novels/[genre].tsx

@@ -10,6 +10,7 @@ import type { ListItem } from "../../types/http";
 import NovelItem from "../../components/NovelItem";
 
 import styles from "../../styles/genre.module.scss";
+import { get } from "../../utils/http";
 
 const Genre = () => {
   const { query } = useRouter();
@@ -64,7 +65,7 @@ export const getServerSideProps: GetServerSideProps<
   { genre: string }
 > = async ({ params }) => {
   const key = params?.genre ? `/api/genre/${params.genre}` : `/api/list`;
-  const data = await fetch(key).then((res) => res.json());
+  const data = await get(key);
 
   return {
     props: {