diff --git a/next.config.mjs b/next.config.mjs index 05e4467..c7a3525 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -3,6 +3,7 @@ import analyzer from '@next/bundle-analyzer'; import { execSync } from 'child_process'; import webpack from 'webpack'; import createNextIntlPlugin from 'next-intl/plugin'; +import url from 'url'; const withNextIntl = createNextIntlPlugin(); @@ -44,6 +45,20 @@ const banner = `${bannerFlag} @date ${Date.now()} @hash ${process.env.GITHUB_SHA || getLastCommitHash()}`; +//proxy config +const OIDCURL = process.env.OIDC_SERVER_URL; +const OIDCObj = url.parse(OIDCURL); +const APIPrefix = process.env.API_PREFIX; +const proxyTarget = `${OIDCObj.protocol}//${OIDCObj.host}`; +const proxyPath = [ + APIPrefix +]; + +const proxyConfigs = proxyPath.map(path => ({ + source: `${path}/:path*`, + destination: `${proxyTarget}${path}/:path*` +})); + const nextConfig = { compress: isProd, typescript: { @@ -96,6 +111,10 @@ const nextConfig = { return config; }, + + async rewrites() { + return !isProd ? proxyConfigs : []; + }, } export default isProd ? diff --git a/package.json b/package.json index fc0ca27..5494443 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "scripts": { "build": "next build", "build:analyze": "cross-env ANALYZE=true next build", - "dev": "node server.mjs", + "dev": "next dev", "lint": "npm run lint:es && npm run lint:style", "lint-fix": "npm run lint-fix:es && npm run lint-fix:style", "lint-fix:es": "eslint --ext .jsx,.js,.tsx,.ts src --fix", diff --git a/src/middleware.ts b/src/middleware.ts index 7d0d6d0..d0aec28 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -4,7 +4,14 @@ import { NextRequest } from 'next/server'; import { locales } from './i18n'; import { LOCALE } from './utils/constants'; +const isProd = process.env.NODE_ENV === 'production'; +const APIPrefix = process.env.API_PREFIX; + export default async function middleware(request: NextRequest) { + if (!isProd && request.nextUrl.pathname.startsWith(APIPrefix)) { + return; + } + const acceptLanguage = request.headers.get('accept-language')?.split(';')?.[0]?.split(',')?.[0]?.split('-')?.[0] || ''; const defaultLocale: string =