Skip to content

Commit f8079b8

Browse files
authored
Merge pull request #51 from wafflestudio/50-feature-api-test-page
api 연결 테스트 페이지 생성
2 parents 52e29b4 + 1312a72 commit f8079b8

File tree

9 files changed

+77
-8
lines changed

9 files changed

+77
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ dist-ssr
2222
*.njsproj
2323
*.sln
2424
*.sw?
25+
26+
.env

src/app/providers/Providers.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ import { ThemeProvider } from 'next-themes'
44

55
import { SidebarProvider } from '@/shared/ui/sidebar'
66
import { Toaster } from '@/shared/ui/sonner'
7+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
8+
9+
const queryClient = new QueryClient()
710

811
export function Providers({ children }: PropsWithChildren) {
912
return (
10-
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
11-
<SidebarProvider>{children}</SidebarProvider>
12-
<Toaster duration={1500} className="text-center" />
13-
</ThemeProvider>
13+
<QueryClientProvider client={queryClient}>
14+
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
15+
<SidebarProvider>{children}</SidebarProvider>
16+
<Toaster duration={1500} className="text-center" />
17+
</ThemeProvider>
18+
</QueryClientProvider>
1419
)
1520
}

src/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ async function enableMocking() {
88
if (import.meta.env.DEV) {
99
const { worker } = await import('./mocks/browser')
1010
return worker.start({
11-
onUnhandledRequest: 'bypass',
11+
onUnhandledRequest: 'warn',
1212
})
1313
}
1414
}

src/mocks/handlers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
import { postHandlers } from './handlers/post'
2+
import { testHandlers } from './handlers/test'
23

3-
export const handlers = [...postHandlers]
4+
export const handlers = [...postHandlers, ...testHandlers]

src/mocks/handlers/test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { http, HttpResponse } from 'msw'
2+
3+
export const testHandlers = [
4+
http.get('*/actuator/health', () => {
5+
return HttpResponse.json({ status: 'ok' })
6+
}),
7+
]

src/routeTree.gen.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { Route as AppRouteImport } from './routes/_app'
1414
import { Route as AppIndexRouteImport } from './routes/_app/index'
1515
import { Route as PasswordResetRouteImport } from './routes/password/reset'
1616
import { Route as AccountsEmailsignupRouteImport } from './routes/accounts/emailsignup'
17+
import { Route as AppTestRouteImport } from './routes/_app/test'
1718
import { Route as AppExploreRouteImport } from './routes/_app/explore'
1819
import { Route as AppProfile_nameRouteImport } from './routes/_app/$profile_name'
1920
import { Route as AppProfile_nameIndexRouteImport } from './routes/_app/$profile_name/index'
@@ -45,6 +46,11 @@ const AccountsEmailsignupRoute = AccountsEmailsignupRouteImport.update({
4546
path: '/accounts/emailsignup',
4647
getParentRoute: () => rootRouteImport,
4748
} as any)
49+
const AppTestRoute = AppTestRouteImport.update({
50+
id: '/test',
51+
path: '/test',
52+
getParentRoute: () => AppRoute,
53+
} as any)
4854
const AppExploreRoute = AppExploreRouteImport.update({
4955
id: '/explore',
5056
path: '/explore',
@@ -81,6 +87,7 @@ export interface FileRoutesByFullPath {
8187
'/login': typeof LoginRoute
8288
'/$profile_name': typeof AppProfile_nameRouteWithChildren
8389
'/explore': typeof AppExploreRoute
90+
'/test': typeof AppTestRoute
8491
'/accounts/emailsignup': typeof AccountsEmailsignupRoute
8592
'/password/reset': typeof PasswordResetRoute
8693
'/': typeof AppIndexRoute
@@ -92,6 +99,7 @@ export interface FileRoutesByFullPath {
9299
export interface FileRoutesByTo {
93100
'/login': typeof LoginRoute
94101
'/explore': typeof AppExploreRoute
102+
'/test': typeof AppTestRoute
95103
'/accounts/emailsignup': typeof AccountsEmailsignupRoute
96104
'/password/reset': typeof PasswordResetRoute
97105
'/': typeof AppIndexRoute
@@ -106,6 +114,7 @@ export interface FileRoutesById {
106114
'/login': typeof LoginRoute
107115
'/_app/$profile_name': typeof AppProfile_nameRouteWithChildren
108116
'/_app/explore': typeof AppExploreRoute
117+
'/_app/test': typeof AppTestRoute
109118
'/accounts/emailsignup': typeof AccountsEmailsignupRoute
110119
'/password/reset': typeof PasswordResetRoute
111120
'/_app/': typeof AppIndexRoute
@@ -120,6 +129,7 @@ export interface FileRouteTypes {
120129
| '/login'
121130
| '/$profile_name'
122131
| '/explore'
132+
| '/test'
123133
| '/accounts/emailsignup'
124134
| '/password/reset'
125135
| '/'
@@ -131,6 +141,7 @@ export interface FileRouteTypes {
131141
to:
132142
| '/login'
133143
| '/explore'
144+
| '/test'
134145
| '/accounts/emailsignup'
135146
| '/password/reset'
136147
| '/'
@@ -144,6 +155,7 @@ export interface FileRouteTypes {
144155
| '/login'
145156
| '/_app/$profile_name'
146157
| '/_app/explore'
158+
| '/_app/test'
147159
| '/accounts/emailsignup'
148160
| '/password/reset'
149161
| '/_app/'
@@ -198,6 +210,13 @@ declare module '@tanstack/react-router' {
198210
preLoaderRoute: typeof AccountsEmailsignupRouteImport
199211
parentRoute: typeof rootRouteImport
200212
}
213+
'/_app/test': {
214+
id: '/_app/test'
215+
path: '/test'
216+
fullPath: '/test'
217+
preLoaderRoute: typeof AppTestRouteImport
218+
parentRoute: typeof AppRoute
219+
}
201220
'/_app/explore': {
202221
id: '/_app/explore'
203222
path: '/explore'
@@ -254,19 +273,21 @@ const AppProfile_nameRouteChildren: AppProfile_nameRouteChildren = {
254273
}
255274

256275
const AppProfile_nameRouteWithChildren = AppProfile_nameRoute._addFileChildren(
257-
AppProfile_nameRouteChildren,
276+
AppProfile_nameRouteChildren
258277
)
259278

260279
interface AppRouteChildren {
261280
AppProfile_nameRoute: typeof AppProfile_nameRouteWithChildren
262281
AppExploreRoute: typeof AppExploreRoute
282+
AppTestRoute: typeof AppTestRoute
263283
AppIndexRoute: typeof AppIndexRoute
264284
AppPProfile_nameRoute: typeof AppPProfile_nameRoute
265285
}
266286

267287
const AppRouteChildren: AppRouteChildren = {
268288
AppProfile_nameRoute: AppProfile_nameRouteWithChildren,
269289
AppExploreRoute: AppExploreRoute,
290+
AppTestRoute: AppTestRoute,
270291
AppIndexRoute: AppIndexRoute,
271292
AppPProfile_nameRoute: AppPProfile_nameRoute,
272293
}

src/routes/_app/test.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { createFileRoute } from '@tanstack/react-router'
2+
3+
import { useQuery } from '@tanstack/react-query'
4+
import { getTest } from '@/shared/api/test'
5+
6+
export const Route = createFileRoute('/_app/test')({
7+
component: RouteComponent,
8+
})
9+
10+
function RouteComponent() {
11+
const { data, isLoading, error } = useQuery({
12+
queryKey: ['test'],
13+
queryFn: getTest,
14+
retry: false,
15+
})
16+
17+
if (isLoading) return <div>Loading...</div>
18+
if (error) return <div>Error: {error.message}</div>
19+
return <div>Data: {JSON.stringify(data)}</div>
20+
}

src/shared/api/test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { instance } from './ky'
2+
3+
export const getTest = async () => {
4+
const response = await instance.get('actuator/health')
5+
return response.json()
6+
}

vite.config.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ import { tanstackRouter } from '@tanstack/router-plugin/vite'
66

77
// https://vite.dev/config/
88
export default defineConfig({
9-
plugins: [tanstackRouter(), react(), tailwindcss()],
9+
plugins: [
10+
tanstackRouter({
11+
routesDirectory: './src/routes',
12+
generatedRouteTree: './src/routeTree.gen.ts',
13+
}),
14+
react(),
15+
tailwindcss(),
16+
],
1017
test: {
1118
globals: true,
1219
environment: 'jsdom',

0 commit comments

Comments
 (0)