-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathnext.config.js
93 lines (88 loc) · 2.73 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
const withBundleAnalyzer = require("@next/bundle-analyzer")({
enabled: process.env.ANALYZE === "true"
});
/**
* @type {import('next').NextConfig}
*/
const config = {
productionBrowserSourceMaps: true,
env: {
// make the backend URL available to the frontend
NEXT_PUBLIC_BACKEND_URL: process.env.BACKEND_URL,
NEXT_PUBLIC_ACCOUNTS_URL: "https://accounts.flanksource.com"
},
redirects: async () => {
if (process.env.NEXT_PUBLIC_APP_DEPLOYMENT === "CANARY_CHECKER") {
return [];
}
// Redirect early, for a better user experience
return [
{
source: "/config/:path*",
destination: "/catalog/:path*",
permanent: true
},
{
source: "/settings/notifications/:path*",
destination: "/notifications/:path*",
permanent: true
}
];
},
async rewrites() {
// if clerk is enabled, we will use next API routes to proxy requests to
// the backend
if (process.env.NEXT_PUBLIC_AUTH_IS_CLERK === "true") {
return [];
}
// Read at build time. See Dockerfile for deployment related steps.
const backendURL = process.env.BACKEND_URL || "http://localhost:3000/";
const isCanary =
process.env.NEXT_PUBLIC_APP_DEPLOYMENT === "CANARY_CHECKER";
const canaryPrefix = isCanary ? "" : "/canary";
const LOCALHOST_ENV_URL_REWRITES = [
{
source: "/api/:path*",
destination: `${backendURL}/api/:path*`
}
];
const URL_REWRITES = [
{
source: "/api/canary/:path*",
destination: `${backendURL}/${canaryPrefix}/:path*`
},
{
source: "/api/.ory/:path*",
destination: `${backendURL}/kratos/:path*`
},
// All other API requests are proxied to the backend on the same path
// as the request.
{
source: "/api/:path*",
destination: `${backendURL}/:path*`
}
];
// NODE_ENV is set to "development" when running locally, so we can use it
// to determine if we are running in a local environment.
const rewrites = ["localhost", "netlify", "development"].includes(
process.env.ENV || process.env.NODE_ENV
)
? LOCALHOST_ENV_URL_REWRITES
: URL_REWRITES;
return rewrites;
},
// https://github.com/vercel/next.js/tree/canary/examples/with-docker#in-existing-projects
...(process.env.NEXT_STANDALONE_DEPLOYMENT === "true"
? {
output: "standalone"
}
: {}),
experimental: {
// increase the default timeout for the proxy from 30s to 10m to allow for
// long running requests to the backend
proxyTimeout: 1000 * 60 * 10,
esmExternals: "loose"
},
transpilePackages: ["monaco-editor", "@flanksource/icons"]
};
module.exports = withBundleAnalyzer(config);