gendesign/tradein-mvp/frontend/next.config.ts
bot-backend f937f5a168
All checks were successful
CI / changes (pull_request) Successful in 9s
CI / backend-tests (pull_request) Has been skipped
CI / openapi-codegen-check (pull_request) Has been skipped
CI / frontend-tests (pull_request) Has been skipped
fix(tradein/frontend): redirect legacy /trade-in root to canonical /v2
Оценщики клиента должны попадать на новую витрину /trade-in/v2 (wired на
real data), а не на легаси-корень (app/page.tsx, HeroSummary). Добавляю
декларативный redirects() в next.config: source "/" -> destination "/v2".

- permanent:false -> 307 (обратимо, не кэшируется навсегда)
- basePath авто-префиксит -> редирект /trade-in -> /trade-in/v2
- query-string Next пробрасывает автоматически (destination без своего
  query) -> /trade-in/?id=<uuid> -> /trade-in/v2?id=<uuid>, restore
  оценки по ?id= не ломается (v2 читает ?id= через window.location.search)
- легаси page.tsx / компоненты остаются в репо (только редирект, обратимо)
2026-07-02 19:26:55 +03:00

42 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { NextConfig } from "next";
// basePath: пусто в dev / `/trade-in` в production когда сидим под gendsgn.ru/trade-in.
// Прокидывается через env при сборке Docker.
const BASE_PATH = process.env.NEXT_PUBLIC_BASE_PATH ?? "";
const nextConfig: NextConfig = {
reactStrictMode: true,
output: "standalone",
// basePath сдвигает ВСЕ routes на /trade-in/* — Next сам префиксит ассеты
// и navigation. Пустая строка = no-op.
basePath: BASE_PATH || undefined,
// assetPrefix — для CDN (мы не используем, оставляем пустым)
// trailingSlash — false (default), важно чтобы Caddy /trade-in без слэша
// редиректил на /trade-in/.
// Каноничная витрина = /v2. Легаси-корень (app/page.tsx, HeroSummary)
// остаётся в репо, но корень редиректит на /v2, чтобы оценщики попадали
// сразу на новую версию. permanent:false → 307 (обратимо, не кэшируется
// навсегда). basePath авто-префиксит source/destination → редирект живёт
// на /trade-in → /trade-in/v2. Query-string Next пробрасывает автоматически
// (destination без своего query), поэтому /trade-in/?id=<uuid> →
// /trade-in/v2?id=<uuid> — ссылки на конкретную оценку (restore по ?id=)
// не ломаются.
async redirects() {
return [{ source: "/", destination: "/v2", permanent: false }];
},
// В dev (без Caddy) Next.js сам проксирует /api/* и /health на backend
// так что браузер использует относительные same-origin URLs.
async rewrites() {
const backend = process.env.BACKEND_URL ?? "http://localhost:8000";
return [
{ source: "/api/:path*", destination: `${backend}/api/:path*` },
{ source: "/health", destination: `${backend}/health` },
];
},
};
export default nextConfig;