This repository was archived by the owner on Apr 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathnext.config.js
More file actions
94 lines (85 loc) · 2.77 KB
/
Copy pathnext.config.js
File metadata and controls
94 lines (85 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const path = require('path');
const getLocales = require('./scripts/get-locales');
// Load the .env file for local development
// .env.development.local by default
require('dotenv').config({
path: path.resolve(process.cwd(), '.env.development.local'),
});
if (
process.env.BACKEND_URL === undefined &&
process.env.PANTHEON_CMS_ENDPOINT === undefined
) {
let message;
if (process.env.NODE_ENV === 'development') {
message = `No BACKEND_URL found.\nSee the README.md for information on setting this variable locally.`;
} else if (process.env.NODE_ENV === 'production') {
message = `No CMS Endpoint found.\nLink a CMS or set the BACKEND_URL environment variable in the settings tab in the dashboard\nIf your site does not require a backend to build, remove this check from the next.config.js.`;
}
throw new Error(message);
}
// if the FRONTEND_URL is not set, fallback to the PANTHEON_ENVIRONMENT_URL
if (
process.env.FRONTEND_URL === undefined &&
process.env.PANTHEON_ENVIRONMENT_URL
) {
process.env.FRONTEND_URL = process.env.PANTHEON_ENVIRONMENT_URL;
}
let backendUrl, imageDomain;
if (process.env.BACKEND_URL === undefined) {
backendUrl = `https://${process.env.PANTHEON_CMS_ENDPOINT}`;
imageDomain = process.env.IMAGE_DOMAIN || process.env.PANTHEON_CMS_ENDPOINT;
// populate BACKEND_URL as a fallback and for build scripts
process.env.BACKEND_URL = `https://${process.env.PANTHEON_CMS_ENDPOINT}`;
} else {
backendUrl = process.env.BACKEND_URL;
imageDomain =
process.env.IMAGE_DOMAIN ||
process.env.BACKEND_URL.replace(/^https?:\/\//, '');
}
// remove trailing slash if it exists
imageDomain = imageDomain.replace(/\/$/, '');
// expose FRONTEND_URL to properly set hrefLang
// and remove trailing slash
process.env.NEXT_PUBLIC_FRONTEND_URL = process.env.FRONTEND_URL
? process.env.FRONTEND_URL?.replace(/\/$/, '')
: '';
const injectedOptions = {};
if (process.env.PANTHEON_UPLOAD_PATH) {
injectedOptions['basePath'] = process.env.PANTHEON_UPLOAD_PATH;
}
module.exports = async () => {
const locales = await getLocales();
const nextConfig = {
...(injectedOptions && injectedOptions),
env: {
backendUrl: backendUrl,
// set imageUrl if IMAGE_DOMAIN is set in env vars to override default
imageUrl: `https://${imageDomain}`,
// makes locales available to lib/stores.js
locales: locales,
},
reactStrictMode: true,
images: {
domains: [imageDomain],
},
i18n: {
locales: locales,
defaultLocale: 'en',
},
output: 'standalone',
async rewrites() {
return [
{
// inline-images can still be fetched from their source
source: '/sites/default/:path*',
destination: `${backendUrl}/sites/default/:path*`,
},
];
},
transpilePackages: [
'@pantheon-systems/nextjs-kit',
'@pantheon-systems/drupal-kit',
],
};
return nextConfig;
};