Skip to content

Commit da48b8d

Browse files
j-muellerKJES4
andauthored
update nextjs config file (#81)
Co-authored-by: KJES4 <[email protected]>
1 parent 6ae2dc6 commit da48b8d

File tree

1 file changed

+58
-86
lines changed

1 file changed

+58
-86
lines changed

frontend/next.config.js

+58-86
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
/** @type {import('next').NextConfig} */
2+
const { PHASE_DEVELOPMENT_SERVER } = require('next/constants');
13
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
24

35
/**
4-
* Webpack config used by export and dev builds
6+
* Webpack config used in all environments
57
* @param {*} config
68
* @param {*} param1
79
* @returns
@@ -24,95 +26,65 @@ const webpackConfig = (config, { isServer }) => {
2426
if (!isServer) {
2527
config.output.environment = { ...config.output.environment, asyncFunction: true };
2628
}
27-
28-
// Add fallback and resolve configurations for browser compatibility
29-
config.resolve = {
30-
...config.resolve,
31-
extensions: ['.ts', '.tsx', '.js', '.mjs'],
32-
fallback: {
33-
https: require.resolve('https-browserify'),
34-
http: require.resolve('stream-http'),
35-
'get-port-please': false,
36-
net: false,
37-
fs: false,
38-
os: false,
39-
path: false,
40-
events: require.resolve('events/'),
41-
buffer: require.resolve('buffer/'),
42-
stream: require.resolve('readable-stream'),
43-
crypto: require.resolve('crypto-browserify'),
44-
constants: require.resolve('constants-browserify'),
45-
zlib: require.resolve('browserify-zlib'),
46-
dns: false,
47-
tls: false,
48-
process: false,
49-
child_process: false,
50-
},
51-
};
5229

5330
return config;
5431
};
5532

56-
/**
57-
* Next.js config that produces a static page
58-
*/
59-
const nextConfigExport = {
60-
output: 'export',
61-
webpack: webpackConfig,
62-
experimental: {
63-
esmExternals: true, // Ensure modern module support
64-
},
65-
66-
// https://github.com/Anastasia-Labs/lucid-evolution/issues/437
67-
serverExternalPackages: [
68-
"@lucid-evolution/lucid"
69-
]
70-
}
71-
72-
/** @type {import('next').NextConfig} */
73-
const nextConfigDev = {
74-
// output: 'export',
75-
serverExternalPackages: [
76-
"@lucid-evolution/lucid",
77-
],
78-
async headers() {
79-
return [
80-
{
81-
// matching all API routes
82-
source: "/api/v1/:path*",
83-
headers: [
84-
{ key: "Access-Control-Allow-Credentials", value: "true" },
85-
{ key: "Access-Control-Allow-Origin", value: "*" },
86-
{ key: "Access-Control-Allow-Methods", value: "GET,OPTIONS,PATCH,DELETE,POST,PUT" },
87-
{ key: "Access-Control-Allow-Headers", value: "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version" },
33+
module.exports = (phase, {defaultConfig}) => {
34+
if (phase === PHASE_DEVELOPMENT_SERVER) {
35+
return {
36+
/* NextJS development-only config options here */
37+
serverExternalPackages: [
38+
"@lucid-evolution/lucid",
39+
],
40+
async headers() {
41+
return [
42+
{
43+
// matching all API routes
44+
source: "/api/v1/:path*",
45+
headers: [
46+
{ key: "Access-Control-Allow-Credentials", value: "true" },
47+
{ key: "Access-Control-Allow-Origin", value: "*" },
48+
{ key: "Access-Control-Allow-Methods", value: "GET,OPTIONS,PATCH,DELETE,POST,PUT" },
49+
{ key: "Access-Control-Allow-Headers", value: "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version" },
50+
]
51+
}
8852
]
89-
}
90-
]
91-
},
92-
async rewrites() {
93-
return [
94-
{
95-
source: '/api/v1/:path*', // Match all routes starting with /api/v1/
96-
destination: 'http://localhost:8080/api/v1/:path*', // Proxy to backend server
9753
},
98-
];
99-
},
100-
async redirects() {
101-
return [
102-
{
103-
source: '/',
104-
destination: '/mint-authority',
105-
permanent: true, // Use true for a 301 redirect, false for 302
54+
async rewrites() {
55+
return [
56+
{
57+
source: '/api/v1/:path*', // Match all routes starting with /api/v1/
58+
destination: 'http://localhost:8080/api/v1/:path*', // Proxy to backend server
59+
},
60+
];
10661
},
107-
];
108-
},
109-
experimental: {
110-
esmExternals: true, // Ensure modern module support
111-
},
112-
webpack: webpackConfig
113-
};
114-
115-
const nextConfig = (process.env.WST_BUILD === 'export') ? nextConfigExport : nextConfigDev;
116-
117-
module.exports = nextConfig;
118-
62+
async redirects() {
63+
return [
64+
{
65+
source: '/',
66+
destination: '/mint-authority',
67+
permanent: true, // Use true for a 301 redirect, false for 302
68+
},
69+
];
70+
},
71+
experimental: {
72+
esmExternals: true, // Ensure modern module support
73+
},
74+
webpack: webpackConfig
75+
}
76+
}
77+
// Default NextJS config for other phases (e.g., production, static export)
78+
return {
79+
output: 'export',
80+
webpack: webpackConfig,
81+
experimental: {
82+
esmExternals: true, // Ensure modern module support
83+
},
84+
85+
// https://github.com/Anastasia-Labs/lucid-evolution/issues/437
86+
serverExternalPackages: [
87+
"@lucid-evolution/lucid"
88+
]
89+
}
90+
}

0 commit comments

Comments
 (0)