infoalloggi-monorepo/apps/infoalloggi/next.config.ts
Marco Pedone 699579b432 feat: update environment variable handling and dependencies
- 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.
2025-10-20 16:22:20 +02:00

109 lines
2.5 KiB
TypeScript

/**
* 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<NextConfig> {
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
},
env: {
NEXT_PUBLIC_BUILD_ID: Math.random().toString(36).slice(2, 8),
},
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 [
{
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:
"(?<token>^[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:
"(?<token>^[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())();