diff --git a/moon/apps/web/hooks/useTestInfo.ts b/moon/apps/web/hooks/useTestInfo.ts new file mode 100644 index 000000000..791f29ee8 --- /dev/null +++ b/moon/apps/web/hooks/useTestInfo.ts @@ -0,0 +1,25 @@ +import { useQuery } from '@tanstack/react-query' +import { legacyApiClient } from '@/utils/queryClient' + +interface TestAPIResponse { + req_result: boolean; + data: Data[]; + err_message: string; +} + +interface Data { + oid: string; + name: string; + content_type: string; + message: string; + date: string; +} + +export function useTestInfo(path: string) { + return useQuery({ + queryKey: ['path', path], + queryFn: () => + fetch(`${legacyApiClient.baseUrl}/api/v1/tree/commit-info?path=${path}`) + .then(res => res.json() as Promise) + }) +} \ No newline at end of file diff --git a/moon/apps/web/next.config.js b/moon/apps/web/next.config.js index 2198064ed..9ed0f9ce4 100644 --- a/moon/apps/web/next.config.js +++ b/moon/apps/web/next.config.js @@ -36,6 +36,7 @@ const cspResourcesByDirective = { 'https://*.gitmono.com', 'wss://*.gitmono.com', process.env.NODE_ENV !== 'production' && 'http://api.gitmega.com', + process.env.NODE_ENV !== 'production' && 'http://git.gitmega.com', process.env.NODE_ENV !== 'production' && 'ws://localhost:9000', 'https://gitmono.s3.ap-southeast-2.amazonaws.com', process.env.NODE_ENV !== 'production' && 'https://campsite-media-dev.s3.amazonaws.com', diff --git a/moon/apps/web/pages/[org]/testapi/index.tsx b/moon/apps/web/pages/[org]/testapi/index.tsx new file mode 100644 index 000000000..936c26091 --- /dev/null +++ b/moon/apps/web/pages/[org]/testapi/index.tsx @@ -0,0 +1,37 @@ +import Head from 'next/head' +import { AppLayout } from '@/components/Layout/AppLayout' +import AuthAppProviders from '@/components/Providers/AuthAppProviders' +import { useTestInfo } from '@/hooks/useTestInfo' +import { PageWithLayout } from '@/utils/types' + +const TestApiPage: PageWithLayout = () => { + const { data, isLoading, error } = useTestInfo('/third-part') + + return ( + <> + + API Test Page + +
+

API Test Results

+ {isLoading &&
Loading...
} + {error &&
Error: {error.message}
} + {data && ( +
+
{JSON.stringify(data, null, 2)}
+
+ )} +
+ + ) +} + +TestApiPage.getProviders = (page, pageProps) => { + return ( + + {page} + + ) +} + +export default TestApiPage diff --git a/moon/apps/web/utils/queryClient.ts b/moon/apps/web/utils/queryClient.ts index cf9a6eab1..2853e8413 100644 --- a/moon/apps/web/utils/queryClient.ts +++ b/moon/apps/web/utils/queryClient.ts @@ -1,6 +1,6 @@ import { InfiniteData, QueryClient, QueryKey } from '@tanstack/react-query' -import { RAILS_API_URL, RAILS_AUTH_URL } from '@gitmono/config' +import { RAILS_API_URL, RAILS_AUTH_URL, LEGACY_API_URL } from '@gitmono/config' import { Api, ApiError, DataTag } from '@gitmono/types' import { ApiErrorResponse } from './types' @@ -146,6 +146,15 @@ export const apiClient = new Api({ } }) +export const legacyApiClient = new Api({ + baseUrl: LEGACY_API_URL, + baseApiParams: { + credentials: 'include', + headers: { 'Content-Type': 'application/json' }, + format: 'json' + } +}) + type NoInfer = [T][T extends any ? 0 : never] type Updater = T | undefined | ((old: T | undefined) => T | undefined) diff --git a/moon/packages/config/src/index.ts b/moon/packages/config/src/index.ts index 1086e76ad..78858f29e 100644 --- a/moon/packages/config/src/index.ts +++ b/moon/packages/config/src/index.ts @@ -24,6 +24,10 @@ export const RAILS_API_URL = IS_PRODUCTION ? 'https://api.gitmono.com' : process.env.NEXT_PUBLIC_API_URL || 'http://api.gitmega.com' +export const LEGACY_API_URL = IS_PRODUCTION + ? 'https://api.gitmono.com' + : process.env.NEXT_PUBLIC_LEGACY_API_URL || 'http://git.gitmega.com' + const RAILS_AUTH_URL_PROD_COM = 'https://auth.gitmono.com' export const RAILS_AUTH_URL = IS_PRODUCTION