Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions moon/apps/web/hooks/useTestInfo.ts
Original file line number Diff line number Diff line change
@@ -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<TestAPIResponse>)
})
}
1 change: 1 addition & 0 deletions moon/apps/web/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
37 changes: 37 additions & 0 deletions moon/apps/web/pages/[org]/testapi/index.tsx
Original file line number Diff line number Diff line change
@@ -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<any> = () => {
const { data, isLoading, error } = useTestInfo('/third-part')

return (
<>
<Head>
<title>API Test Page</title>
</Head>
<div className="p-4">
<h1 className="text-2xl font-bold mb-4">API Test Results</h1>
{isLoading && <div>Loading...</div>}
{error && <div className="text-red-500">Error: {error.message}</div>}
{data && (
<div className="bg-gray-100 p-4 rounded">
<pre>{JSON.stringify(data, null, 2)}</pre>
</div>
)}
</div>
</>
)
}

TestApiPage.getProviders = (page, pageProps) => {
return (
<AuthAppProviders {...pageProps}>
<AppLayout {...pageProps}>{page}</AppLayout>
</AuthAppProviders>
)
}

export default TestApiPage
11 changes: 10 additions & 1 deletion moon/apps/web/utils/queryClient.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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][T extends any ? 0 : never]
type Updater<T> = T | undefined | ((old: T | undefined) => T | undefined)

Expand Down
4 changes: 4 additions & 0 deletions moon/packages/config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down