Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion client/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ EXPOSE 3000
CMD ["npm", "run", "start"]

FROM node:20.4.0-alpine3.18 AS dev
ENV API_URL=http://app:8000
WORKDIR /client

COPY package.json package-lock.json ./
Expand Down
10 changes: 0 additions & 10 deletions client/next.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
const API_URL = process.env.API_URL;

module.exports = {
async rewrites() {
return [
{
source: "/api/:path*",
destination: `${API_URL}/api/:path*`,
},
];
},
output: "standalone",
};
47 changes: 47 additions & 0 deletions client/src/app/api/[...path]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { NextRequest, NextResponse } from "next/server";

const API_URL = process.env.API_URL;
const API_KEY = process.env.API_KEY;

async function proxyRequest(req: NextRequest) {
const url = new URL(req.url);
const path = url.pathname;
const search = url.search;
const destination = `${API_URL}/v1/${path}${search}`;

const headers = new Headers();
headers.set("Accept", "application/json");
headers.set("Content-Type", "application/json");

if (API_KEY) {
headers.set("Authorization", `Bearer ${API_KEY}`);
}

const body =
req.method !== "GET" && req.method !== "HEAD"
? await req.text()
: undefined;

const response = await fetch(destination, {
method: req.method,
headers,
body,
});

const data = await response.text();

return new NextResponse(data, {
status: response.status,
statusText: response.statusText,
headers: {
"Content-Type":
response.headers.get("Content-Type") || "application/json",
},
});
}

export const GET = proxyRequest;
export const POST = proxyRequest;
export const PATCH = proxyRequest;
export const PUT = proxyRequest;
export const DELETE = proxyRequest;
Loading