diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 0d55c7e..2200211 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -13,10 +13,6 @@ RUN npm install # Copy the rest of the application COPY . . -# Set the API URL for the build -ARG NEXT_PUBLIC_API_URL=/api -ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} - # Build the Next.js application RUN npm run build diff --git a/frontend/jest.setup.js b/frontend/jest.setup.js index 16c8e94..c44951a 100644 --- a/frontend/jest.setup.js +++ b/frontend/jest.setup.js @@ -1,18 +1 @@ -import '@testing-library/jest-dom'; -import fetchMock from 'jest-fetch-mock'; - -fetchMock.enableMocks(); - -Object.defineProperty(window, 'matchMedia', { - writable: true, - value: jest.fn().mockImplementation(query => ({ - matches: false, - media: query, - onchange: null, - addListener: jest.fn(), // deprecated - removeListener: jest.fn(), // deprecated - addEventListener: jest.fn(), - removeEventListener: jest.fn(), - dispatchEvent: jest.fn(), - })), -}); +import '@testing-library/jest-dom' diff --git a/frontend/next.config.ts b/frontend/next.config.ts index c74c8ac..cb651cd 100644 --- a/frontend/next.config.ts +++ b/frontend/next.config.ts @@ -1,15 +1,5 @@ import type { NextConfig } from "next"; -const nextConfig: NextConfig = { - async rewrites() { - const backendUrl = process.env.LETTERFEED_BACKEND_URL || "http://backend:8000"; - return [ - { - source: "/api/:path*", - destination: `${backendUrl}/:path*`, - }, - ]; - }, -}; +const nextConfig: NextConfig = {}; export default nextConfig; diff --git a/frontend/src/lib/__tests__/api.test.ts b/frontend/src/lib/__tests__/api.test.ts index c71a699..869c5f5 100644 --- a/frontend/src/lib/__tests__/api.test.ts +++ b/frontend/src/lib/__tests__/api.test.ts @@ -46,7 +46,7 @@ const mockFetchError = (data: any = {}, statusText = "Bad Request", status = 400 } describe("API Functions", () => { - const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL + const API_BASE_URL = '/api' beforeEach(() => { // Reset the mock before each test diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index 9ecd97b..33af48d 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -1,4 +1,4 @@ -const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL; +const API_BASE_URL = '/api'; export interface Sender { id: string; diff --git a/frontend/src/middleware.ts b/frontend/src/middleware.ts new file mode 100644 index 0000000..e52bd92 --- /dev/null +++ b/frontend/src/middleware.ts @@ -0,0 +1,18 @@ +import { NextRequest, NextResponse } from 'next/server'; + +export function middleware(request: NextRequest) { + const backendUrl = process.env.LETTERFEED_BACKEND_URL || 'http://backend:8000'; + + if (request.nextUrl.pathname.startsWith('/api/')) { + const url = request.nextUrl.clone(); + const path = url.pathname.replace('/api', ''); + url.href = `${backendUrl}${path}${url.search}`; + return NextResponse.rewrite(url); + } + + return NextResponse.next(); +} + +export const config = { + matcher: '/api/:path*', +};