added backend reverse proxy to next to directly fetch data from client

This commit is contained in:
Jean Jacques Avril 2025-01-01 10:28:26 +00:00
parent e06753fb24
commit cf3c34fb2f
No known key found for this signature in database
3 changed files with 38 additions and 25 deletions

View File

@ -1,13 +1,23 @@
import type { NextConfig } from "next"; import type { NextConfig } from "next";
import createNextIntlPlugin from 'next-intl/plugin'; import createNextIntlPlugin from "next-intl/plugin";
const withNextIntl = createNextIntlPlugin(); const withNextIntl = createNextIntlPlugin();
const nextConfig: NextConfig = { const nextConfig: NextConfig = {
/* config options here */ /* config options here */
sassOptions: { sassOptions: {
silenceDeprecations: ['legacy-js-api'], silenceDeprecations: ["legacy-js-api"],
} },
async rewrites() {
return [
{
source: "/api/:path*",
destination: `${process.env.API_SERVER}/:path*`, // Zielserver aus Umgebungsvariable
},
];
},
// This is required to support PostHog trailing slash API requests
skipTrailingSlashRedirect: true,
}; };
export default withNextIntl(nextConfig); export default withNextIntl(nextConfig);

View File

@ -1,20 +1,20 @@
import {createNavigation} from 'next-intl/navigation'; import { createNavigation } from "next-intl/navigation";
import {defineRouting} from 'next-intl/routing'; import { defineRouting } from "next-intl/routing";
export const routing = defineRouting({ export const routing = defineRouting({
locales: ['en', 'de'], locales: ["en", "de"],
defaultLocale: 'en', defaultLocale: "en",
pathnames: { pathnames: {
'/': '/', "/": "/",
'/pathnames': { "/pathnames": {
en: '/pathnames', en: "/pathnames",
de: '/pfadnamen' de: "/pfadnamen",
} },
} },
}); });
export type Pathnames = keyof typeof routing.pathnames; export type Pathnames = keyof typeof routing.pathnames;
export type Locale = (typeof routing.locales)[number]; export type Locale = (typeof routing.locales)[number];
export const {Link, getPathname, redirect, usePathname, useRouter} = export const { Link, getPathname, redirect, usePathname, useRouter } =
createNavigation(routing); createNavigation(routing);

View File

@ -1,5 +1,5 @@
import createMiddleware from 'next-intl/middleware'; import createMiddleware from "next-intl/middleware";
import {routing} from './i18n/routing'; import { routing } from "./i18n/routing";
export default createMiddleware(routing); export default createMiddleware(routing);
@ -7,14 +7,17 @@ export const config = {
// Match only internationalized pathnames // Match only internationalized pathnames
matcher: [ matcher: [
// Enable a redirect to a matching locale at the root // Enable a redirect to a matching locale at the root
'/', "/",
// Set a cookie to remember the previous locale for // Set a cookie to remember the previous locale for
// all requests that have a locale prefix // all requests that have a locale prefix
'/(de|en)/:path*', "/(de|en)/:path*",
// Enable redirects that add missing locales // Enable redirects that add missing locales
// (e.g. `/pathnames` -> `/en/pathnames`) // (e.g. `/pathnames` -> `/en/pathnames`)
'/((?!_next|_vercel|.*\\..*).*)' //'/((?!_next|_vercel|.*\\..*).*)'
]
// Ausschließen von API-Routen
"/((?!api|_next|_vercel|.*\\..*).*)",
],
}; };