Skip to content

Commit

Permalink
✨ fetch class 사용 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
oaoong committed Nov 1, 2023
1 parent 8dc20d4 commit 9ff4b43
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 47 deletions.
1 change: 0 additions & 1 deletion src/app/(root)/(routes)/(home)/components/TestBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use client'

import React, { useEffect } from 'react'
// import { useApiClient } from '@/contexts/FetchContext'
import { getTest } from '@/services/test/test'

// async function getTestValue() {
Expand Down
25 changes: 11 additions & 14 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Suspense } from 'react'
import type { Metadata } from 'next'
import Header from '@/components/domain/Header'
import { FetchProvider } from '@/contexts/FetchContext'
import MSWWrapper from '@/contexts/MSWWrapper'
import TanstackQueryContext from '@/contexts/TanstackQueryContext'
import ThemeProviderContext from '@/contexts/ThemeProviderContext'
Expand All @@ -24,19 +23,17 @@ export default function RootLayout({
<html lang="ko">
<body>
<MSWWrapper>
<FetchProvider>
<TanstackQueryContext>
<ThemeProviderContext>
<Suspense fallback={<div>loading...</div>}>
<div className="centered-content">
<Header isLogin={false} />
{children}
{authModal}
</div>
</Suspense>
</ThemeProviderContext>
</TanstackQueryContext>
</FetchProvider>
<TanstackQueryContext>
<ThemeProviderContext>
<Suspense fallback={<div>loading...</div>}>
<div className="centered-content">
<Header isLogin={false} />
{children}
{authModal}
</div>
</Suspense>
</ThemeProviderContext>
</TanstackQueryContext>
</MSWWrapper>
</body>
</html>
Expand Down
26 changes: 0 additions & 26 deletions src/contexts/FetchContext.tsx

This file was deleted.

4 changes: 1 addition & 3 deletions src/lib/fetchAPI.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Environment } from '@/config/environment'

class FetchAPI {
private baseURL: string
private headers: { [key: string]: string }

private static instance: FetchAPI

private constructor() {
this.baseURL = Environment.apiAddress() ?? ''
this.baseURL = ''
this.headers = {
'Content-Type': 'application/json',
}
Expand Down
8 changes: 8 additions & 0 deletions src/services/apiClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Environment } from '@/config/environment'
import FetchAPI from '@/lib/fetchAPI'

const apiClient = FetchAPI.getInstance()
apiClient.setDefaultHeader('Content-Type', 'application/json')
apiClient.setBaseURL(Environment.apiAddress() ?? '')

export default apiClient
5 changes: 2 additions & 3 deletions src/services/test/test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import ApiEndPoint from '@/config/apiEndPoint'
import FetchAPI from '@/lib/fetchAPI'
import apiClient from '../apiClient'

const getTest = async () => {
const api = FetchAPI.getInstance()
const response = await api.get(
const response = await apiClient.get(
ApiEndPoint.test(),
{ next: { revalidate: 10 } },
{
Expand Down

0 comments on commit 9ff4b43

Please sign in to comment.