generated from NHSDigital/nhs-notify-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnext.config.js
More file actions
64 lines (54 loc) · 1.59 KB
/
next.config.js
File metadata and controls
64 lines (54 loc) · 1.59 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
/** @type {import('next').NextConfig} */
const { PHASE_DEVELOPMENT_SERVER } = require('next/constants');
const amplifyConfig = require('./amplify_outputs.json');
const basePath = process.env.NEXT_PUBLIC_BASE_PATH ?? '/templates';
const domain = process.env.NOTIFY_DOMAIN_NAME ?? 'localhost:3000';
const nextConfig = (phase) => {
const isDevServer = phase === PHASE_DEVELOPMENT_SERVER;
const includeAuthPages =
process.env.INCLUDE_AUTH_PAGES === 'true' || isDevServer;
return {
basePath,
env: {
basePath,
BACKEND_API_URL: amplifyConfig?.meta?.backend_api_url,
},
experimental: {
serverActions: {
allowedOrigins: [domain, domain.replace('templates', 'web-gateway')],
},
},
async redirects() {
return [
{
source: '/',
destination: basePath,
basePath: false,
permanent: false,
},
];
},
async rewrites() {
if (includeAuthPages) {
return [
{
source: '/auth/signout',
destination: `http://${domain}${basePath}/auth/signout`,
basePath: false,
},
{
source: '/auth',
destination: `http://${domain}${basePath}/auth`,
basePath: false,
},
];
}
return [];
},
// pages with e.g. .dev.tsx extension are only included when running locally
pageExtensions: ['ts', 'tsx', 'js', 'jsx'].flatMap((extension) => {
return includeAuthPages ? [`dev.${extension}`, extension] : [extension];
}),
};
};
module.exports = nextConfig;