Autonomous multi-agent build/verify drive across gitgram + aitimemachine. All 7 subprojects now build and run; agents fixed real defects throughout. Backend (gitgram/backend): - Migrate to Express 5 typing (ambient .d.ts shims for express-rate-limit, @apollo/server, @trpc/server that resolve Express 5 types under workspace hoisting); fix 2 real GraphQL typing defects; scope typeRoots to local types - Fix startup crash (missing `buffer` pkg required by nsfwjs) - Install ioredis + web-push; build clean, boots (HTTP 200), 1241/1266 tests Web (gitgram/web): next build green (fix route-slug conflict, remove dead lib/trpc.ts); document monorepo dual-React vitest harness limitation (71/86) Mobile (gitgram/mobile): port proximity-unique features (org, starred, reading-list, languages, snippets) onto modern expo-router + axios stack; exclude standalone proximity/ from tsconfig + jest; typecheck clean, 8/8 tests AITM core: fix CLI crash from duplicate command registrations (vendored merge); secure 2 unauthenticated API routes; 520/520 tests AITM api-server: fix ioredis construct + a2a SDK decls + test mocks; 715/715 AITM mcp: fix TS5076 syntax + slow gitnexus import; 63/63 AITM website: next build green (88 routes) Root deps: fix broken @types/uuid stub (real v9), relax override to $@types/uuid Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
106 lines
2.8 KiB
TypeScript
106 lines
2.8 KiB
TypeScript
'use client'
|
|
|
|
import { useEffect, useState } from 'react'
|
|
import { notFound } from 'next/navigation'
|
|
import { AxiosError } from 'axios'
|
|
import api from '@/services/api'
|
|
|
|
/** Result of probing a single backend endpoint. */
|
|
interface EndpointResult {
|
|
status?: number
|
|
data?: unknown
|
|
error?: unknown
|
|
}
|
|
|
|
type Results = Record<string, EndpointResult>
|
|
|
|
function getHealthUrl(): string {
|
|
const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:4000/api'
|
|
return `${apiUrl.replace(/\/?api\/?$/, '')}/health`
|
|
}
|
|
|
|
function toErrorResult(error: unknown): EndpointResult {
|
|
if (error instanceof AxiosError) {
|
|
return { status: error.response?.status, error: error.response?.data ?? error.message }
|
|
}
|
|
if (error instanceof Error) {
|
|
return { error: error.message }
|
|
}
|
|
return { error: 'Unknown error' }
|
|
}
|
|
|
|
/**
|
|
* Developer-only diagnostic page that probes core backend endpoints.
|
|
* Not linked from navigation and gated to non-production builds so it is
|
|
* never a publicly routable page in production.
|
|
*/
|
|
export default function ApiTestPage() {
|
|
const [results, setResults] = useState<Results>({})
|
|
|
|
const isEnabled = process.env.NODE_ENV !== 'production'
|
|
|
|
useEffect(() => {
|
|
if (!isEnabled) return
|
|
|
|
const testEndpoints = async () => {
|
|
const tests: Results = {}
|
|
|
|
try {
|
|
const res = await fetch(getHealthUrl())
|
|
tests.health = { status: res.status, data: await res.json() }
|
|
} catch (error: unknown) {
|
|
tests.health = toErrorResult(error)
|
|
}
|
|
|
|
try {
|
|
const res = await api.get('/auth/me')
|
|
tests.authMe = { status: res.status, data: res.data }
|
|
} catch (error: unknown) {
|
|
tests.authMe = toErrorResult(error)
|
|
}
|
|
|
|
try {
|
|
const res = await api.get('/posts')
|
|
tests.posts = { status: res.status, data: res.data }
|
|
} catch (error: unknown) {
|
|
tests.posts = toErrorResult(error)
|
|
}
|
|
|
|
try {
|
|
const res = await api.get('/github/popular')
|
|
tests.githubPopular = { status: res.status, data: res.data }
|
|
} catch (error: unknown) {
|
|
tests.githubPopular = toErrorResult(error)
|
|
}
|
|
|
|
setResults(tests)
|
|
}
|
|
|
|
void testEndpoints()
|
|
}, [isEnabled])
|
|
|
|
if (!isEnabled) {
|
|
notFound()
|
|
}
|
|
|
|
return (
|
|
<div className="p-8">
|
|
<h1 className="text-2xl font-bold mb-4">API Connection Test</h1>
|
|
<p className="text-sm text-[var(--foreground-secondary)] mb-4">
|
|
Developer diagnostic page (disabled in production).
|
|
</p>
|
|
<div className="space-y-4">
|
|
<div>
|
|
<strong>API Base URL:</strong> {process.env.NEXT_PUBLIC_API_URL || 'Not set'}
|
|
</div>
|
|
<div>
|
|
<strong>Results:</strong>
|
|
<pre className="bg-gray-100 p-4 rounded mt-2 overflow-auto text-black">
|
|
{JSON.stringify(results, null, 2)}
|
|
</pre>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|