fix(rooms): Use rewrite for /api/city/rooms instead of API route
- Removed API route that was conflicting with rewrite - Added explicit rewrite for /api/city/rooms -> /api/v1/city/rooms - Rewrite order matters: specific routes before wildcard
This commit is contained in:
@@ -41,12 +41,18 @@ const nextConfig: NextConfig = {
|
|||||||
source: '/api/public/:path*',
|
source: '/api/public/:path*',
|
||||||
destination: `${internalApiUrl}/public/:path*`,
|
destination: `${internalApiUrl}/public/:path*`,
|
||||||
},
|
},
|
||||||
|
// City Rooms API (list) -> /api/v1/city/rooms
|
||||||
|
// Note: This must be before /api/city/:path* to take precedence
|
||||||
|
{
|
||||||
|
source: '/api/city/rooms',
|
||||||
|
destination: `${internalApiUrl}/api/v1/city/rooms`,
|
||||||
|
},
|
||||||
// City Rooms API (specific slug endpoint) -> /api/v1/city/rooms
|
// City Rooms API (specific slug endpoint) -> /api/v1/city/rooms
|
||||||
{
|
{
|
||||||
source: '/api/city/rooms/:slug',
|
source: '/api/city/rooms/:slug',
|
||||||
destination: `${internalApiUrl}/api/v1/city/rooms/:slug`,
|
destination: `${internalApiUrl}/api/v1/city/rooms/:slug`,
|
||||||
},
|
},
|
||||||
// City API -> /city
|
// City API -> /city (excludes /api/city/rooms which is handled above)
|
||||||
{
|
{
|
||||||
source: '/api/city/:path*',
|
source: '/api/city/:path*',
|
||||||
destination: `${internalApiUrl}/city/:path*`,
|
destination: `${internalApiUrl}/city/:path*`,
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
import { NextRequest, NextResponse } from "next/server";
|
|
||||||
|
|
||||||
const API_BASE = process.env.CITY_API_BASE_URL || process.env.INTERNAL_API_URL;
|
|
||||||
|
|
||||||
export async function GET(_req: NextRequest) {
|
|
||||||
if (!API_BASE) {
|
|
||||||
return NextResponse.json(
|
|
||||||
{ error: "CITY_API_BASE_URL is not configured" },
|
|
||||||
{ status: 500 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const res = await fetch(`${API_BASE}/api/v1/city/rooms`, {
|
|
||||||
method: "GET",
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
cache: "no-store",
|
|
||||||
});
|
|
||||||
|
|
||||||
const data = await res.json().catch(() => null);
|
|
||||||
return NextResponse.json(data, { status: res.status });
|
|
||||||
} catch (error) {
|
|
||||||
console.error("City rooms proxy error:", error);
|
|
||||||
return NextResponse.json(
|
|
||||||
{ error: "Failed to fetch city rooms" },
|
|
||||||
{ status: 502 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user