- Added @t3-oss/env-nextjs for improved environment variable management. - Updated zod to version 4.1.12 for enhanced validation capabilities. - Upgraded jiti to version 2.6.1 for better module loading. - Refactored environment variable imports from env.mjs to env.ts. - Removed deprecated env.mjs file and replaced it with a new env.ts file using @t3-oss/env-nextjs. - Adjusted various components and API routes to utilize the new environment variable structure. - Updated next.config.js to support the new environment variable management. - Modified Docker configuration to align with new BASE_URL handling.
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { type NextRequest, NextResponse } from "next/server";
|
|
import { env } from "~/env";
|
|
|
|
export const apisMiddleware = async (req: NextRequest) => {
|
|
const path = req.nextUrl.pathname;
|
|
|
|
const rewrite_paths = ["/go-api/images/", "/go-api/storage/"];
|
|
if (!rewrite_paths.some((p) => path.startsWith(p))) {
|
|
return;
|
|
}
|
|
|
|
if (
|
|
path.startsWith("/go-api/images/") ||
|
|
path.startsWith("/go-api/storage/")
|
|
) {
|
|
// Handle image and storage requests
|
|
const newPath = path
|
|
.replace("/go-api/images/", "/images/")
|
|
.replace("/go-api/storage/", "/storage/");
|
|
|
|
const url = new URL(`${env.BACKENDSERVER_URL}${newPath}`, req.url);
|
|
const res = NextResponse.rewrite(url);
|
|
res.headers.set("Access-Control-Allow-Origin", env.NEXT_PUBLIC_BASE_URL);
|
|
|
|
res.headers.set(
|
|
"Access-Control-Allow-Methods",
|
|
"GET, POST, PUT, DELETE, OPTIONS",
|
|
);
|
|
res.headers.set(
|
|
"Access-Control-Allow-Headers",
|
|
"Content-Type, Authorization",
|
|
);
|
|
return res;
|
|
|
|
// Fetch the content from the backend and serve it through the middleware
|
|
/*
|
|
const response = await fetch(url.toString(), {
|
|
headers: req.headers,
|
|
});
|
|
|
|
return new NextResponse(response.body, {
|
|
headers: response.headers,
|
|
status: response.status,
|
|
});*/
|
|
}
|
|
};
|