mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-16 06:39:01 +02:00
On self-hosted deployments where the frontend is the public entrypoint, uploaded files return 404 because /uploads/* requests aren't proxied to the backend. Add a rewrite rule following the existing pattern for /api/*, /ws, and /auth/*. Closes #1004
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import type { NextConfig } from "next";
|
|
import { config } from "dotenv";
|
|
import { resolve } from "path";
|
|
|
|
// Load root .env so REMOTE_API_URL is available to next.config.ts
|
|
config({ path: resolve(__dirname, "../../.env") });
|
|
|
|
const remoteApiUrl = process.env.REMOTE_API_URL || "http://localhost:8080";
|
|
|
|
// Parse hostnames from CORS_ALLOWED_ORIGINS so that Next.js dev server
|
|
// allows cross-origin HMR / webpack requests (e.g. from Tailscale IPs).
|
|
const allowedDevOrigins = process.env.CORS_ALLOWED_ORIGINS
|
|
? process.env.CORS_ALLOWED_ORIGINS.split(",")
|
|
.map((origin) => {
|
|
try {
|
|
return new URL(origin.trim()).host;
|
|
} catch {
|
|
return origin.trim();
|
|
}
|
|
})
|
|
.filter(Boolean)
|
|
: undefined;
|
|
|
|
const nextConfig: NextConfig = {
|
|
...(process.env.STANDALONE === "true" ? { output: "standalone" as const } : {}),
|
|
transpilePackages: ["@multica/core", "@multica/ui", "@multica/views"],
|
|
...(allowedDevOrigins && allowedDevOrigins.length > 0
|
|
? { allowedDevOrigins }
|
|
: {}),
|
|
images: {
|
|
formats: ["image/avif", "image/webp"],
|
|
qualities: [75, 80, 85],
|
|
},
|
|
async rewrites() {
|
|
return [
|
|
{
|
|
source: "/api/:path*",
|
|
destination: `${remoteApiUrl}/api/:path*`,
|
|
},
|
|
{
|
|
source: "/ws",
|
|
destination: `${remoteApiUrl}/ws`,
|
|
},
|
|
{
|
|
source: "/auth/:path*",
|
|
destination: `${remoteApiUrl}/auth/:path*`,
|
|
},
|
|
{
|
|
source: "/uploads/:path*",
|
|
destination: `${remoteApiUrl}/uploads/:path*`,
|
|
},
|
|
];
|
|
},
|
|
};
|
|
|
|
export default nextConfig;
|