mirror of
https://github.com/khoaliber/LetterFeed.git
synced 2026-03-05 21:29:12 +00:00
fix: respect LETTERFEED_BACKEND_URL at build time #1
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL;
|
||||
const API_BASE_URL = '/api';
|
||||
|
||||
export interface Sender {
|
||||
id: string;
|
||||
|
||||
18
frontend/src/middleware.ts
Normal file
18
frontend/src/middleware.ts
Normal file
@@ -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*',
|
||||
};
|
||||
Reference in New Issue
Block a user