/
next.config.js
111 lines (104 loc) · 3.11 KB
/
next.config.js
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const { PHASE_PRODUCTION_BUILD, PHASE_DEVELOPMENT_SERVER } = require('next/constants');
const color = require('cli-color');
const { validateData } = require('./data/validate');
const {
OVERRIDE_NODE_ENV = '',
FB_PIXEL_ID,
HIGHSCHOOL_FORM_ACTIVE = 'false',
HIGHSCHOOL_FORM_RESPONSES_NAME = '__TAB_NAME_NOT_SET__',
} = process.env;
const isHsFormActive = HIGHSCHOOL_FORM_ACTIVE?.toLowerCase() === 'true';
module.exports = (phase, { defaultConfig }) => {
console.info(color.magentaBright.bold('\nValidating... '));
if (
!process.env.GITHUB_ACTION &&
[PHASE_PRODUCTION_BUILD, PHASE_DEVELOPMENT_SERVER].includes(phase)
) {
checkEnvVars([
'MAILCHIMP_API_KEY',
'MAILCHIMP_AUDIENCE_ID',
'GREENLIGHT_API_ENDPOINT',
'SIGNUP_API_ENDPOINT',
'GOOGLE_SERVICE_ACCOUNT',
'HIGHSCHOOL_FORM_RESPONSES_ID',
'WUFOO_HOST',
'WUFOO_TOKEN',
'WUFOO_CONTACT_FORM_ID',
'GOOGLE_EVENTS_CALENDAR_ID',
'HIGHSCHOOL_FORM_RESPONSES_NAME',
]);
validateData();
}
if (PHASE_DEVELOPMENT_SERVER === phase) {
const port = process.env.PORT;
console.info(color.blueBright.bold('\nhttp://localhost:' + (port ?? '3000') + '\n'));
}
/**
* @type {import('next').NextConfig}
*/
return {
...defaultConfig,
reactStrictMode: true,
compiler: {
styledComponents: true,
},
env: {
OVERRIDE_NODE_ENV: OVERRIDE_NODE_ENV || '',
FB_PIXEL_ID,
HIGHSCHOOL_FORM_ACTIVE: `${isHsFormActive}`,
HIGHSCHOOL_FORM_RESPONSES_NAME,
},
// TODO: This will need to be updated when NextJS is updated due to change in 12.3.0 (Currently 12.1.0)
// https://nextjs.org/docs/messages/next-image-unconfigured-host
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'storage.googleapis.com',
},
],
},
async redirects() {
return [
{
source: '/info-session',
destination: '/programs/workforce/infoSession',
permanent: true,
},
{
source: '/infoSession',
destination: '/programs/workforce/infoSession',
permanent: true,
},
{
source: `/noladevs`,
destination: '/getInvolved/noladevs',
permanent: false,
},
/**
* High School Application - `/programs/highschool/apply`
* - When high school form is available, set env variable 'HIGHSCHOOL_FORM_ACTIVE' to 'true' otherwise 'false'
*/
!isHsFormActive && {
source: '/programs/highschool/apply',
destination: '/programs/highschool',
permanent: false,
},
{
source: '/privacy',
destination: '/privacyPolicy',
permanent: true,
},
// Filter out false/undefined/null routes
].filter(Boolean);
},
};
};
function checkEnvVars(requiredVars) {
for (const requiredVar of requiredVars) {
if (!process.env[requiredVar]) {
throw new Error(`"${requiredVar}" environment variable not found.`);
}
}
console.info(color.green(' ✓'), 'Validating credentials and data');
}