/** * Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. * This is especially useful for Docker builds. */ import { env } from "node:process"; import { fileURLToPath } from "node:url"; import type { NextConfig } from "next"; async function createNextConfig(): Promise { const { createJiti } = await import("jiti"); const jiti = createJiti(fileURLToPath(import.meta.url)); await jiti.import("./src/env.ts"); return { compiler: { removeConsole: false, }, experimental: { // esmExternals: "loose", // This if react-pdf gives compilation issues }, devIndicators: false, headers: async () => { return [ { headers: [ { key: "X-Frame-Options", value: "", }, ], source: "/:path*", }, ]; }, i18n: { defaultLocale: "it", locales: ["it", "en"], localeDetection: false, }, images: { minimumCacheTTL: 7200, remotePatterns: [ { hostname: "*.googleusercontent.com", pathname: "**", port: "", protocol: "https", }, { hostname: `${env.BACKENDSERVER_URL}`, }, ], }, output: env.NODE_ENV === "production" ? "standalone" : undefined, // This is for docker builds transpilePackages: ["@t3-oss/env-nextjs", "@t3-oss/env-core"], reactStrictMode: true, rewrites: async () => { return [ { source: "/storage/:slug*", destination: "http://localhost:8080/:slug*", }, { destination: env.NODE_ENV === "production" ? "/404" : "/api/panel", source: "/api/panel", }, { destination: `${env.BACKENDSERVER_URL}/images/get/:slug*`, source: "/go-api/images/get/:slug*", }, { destination: `${env.BACKENDSERVER_URL}/storage/get/:slug*`, has: [ { key: "access_token", type: "cookie" }, { key: "token", type: "query", value: "(?^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$)", }, ], source: "/go-api/storage/get/:slug*", }, { destination: `${env.BACKENDSERVER_URL}/storage/upload:slug*`, has: [ { key: "access_token", type: "cookie" }, { key: "token", type: "query", value: "(?^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$)", }, ], source: "/go-api/storage/upload:slug*", }, ]; }, typescript: { ignoreBuildErrors: true, }, }; } export default (async () => await createNextConfig())();