Full-stack Next.js: la home lee MySQL directamente (sin Django)
Pivote a Next.js full-stack (Django saldrá del todo en el cutover). Next accede a las mismas BD MySQL que Django: - lib/db.ts: pools mysql2 (django_wow + acore_*), singleton en globalThis, creds en web-next/.env.local (gitignored, copiadas del .env de Django). - lib/home.ts: getNoticias (home_noticia), getServerStatus (home_serverselection + online desde acore_characters + TCP check + expansión por gamebuild, incl. Classic). - app/page.tsx: home SSR que llama a lib/home (ya NO a la API Django). Se elimina lib/api.ts. Verificado: con el servicio Django PARADO, la home de Next sigue sirviendo 200 con datos reales -> lee MySQL directo, Django fuera del circuito. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,16 +1,13 @@
|
||||
import { apiGet, type Noticia, type ServerStatus } from '@/lib/api'
|
||||
import { getNoticias, getServerStatus, type Noticia, type ServerStatus } from '@/lib/home'
|
||||
|
||||
// SSR por petición: los datos se obtienen en el servidor Next desde la API Django.
|
||||
// (En Next 16 fetch no se cachea por defecto; force-dynamic lo deja explícito.)
|
||||
// SSR por petición: los datos se leen DIRECTAMENTE de MySQL desde el servidor Next
|
||||
// (sin Django). force-dynamic para renderizar por petición.
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
async function getData(): Promise<{ noticias: Noticia[]; status: ServerStatus | null }> {
|
||||
const [news, status] = await Promise.allSettled([
|
||||
apiGet<{ noticias: Noticia[] }>('/api/home/news/'),
|
||||
apiGet<ServerStatus>('/api/home/status/'),
|
||||
])
|
||||
const [news, status] = await Promise.allSettled([getNoticias(), getServerStatus()])
|
||||
return {
|
||||
noticias: news.status === 'fulfilled' ? news.value.noticias : [],
|
||||
noticias: news.status === 'fulfilled' ? news.value : [],
|
||||
status: status.status === 'fulfilled' ? status.value : null,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user