Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace custom server with default server in development #79

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading