Skip to content

Commit

Permalink
refactor: replace custom server with default server in development
Browse files Browse the repository at this point in the history
  • Loading branch information
Fantasy15 committed Apr 7, 2024
1 parent b57e1fb commit 47ec473
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
19 changes: 19 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -96,6 +111,10 @@ const nextConfig = {

return config;
},

async rewrites() {
return !isProd ? proxyConfigs : [];
},
}

export default isProd ?
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 47ec473

Please sign in to comment.