-
Notifications
You must be signed in to change notification settings - Fork 510
/
Copy pathnext.config.js
213 lines (200 loc) · 5.88 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// import reverse from "lodash/reverse";
const fs = require("fs");
const path = require("path");
const IS_DEV = process.env.NODE_ENV === "development";
const PYTHON_DIRECTORY = path.join(process.cwd(), "python/");
const jsonDocstrings = fs.readFileSync(
path.join(PYTHON_DIRECTORY, "streamlit.json"),
"utf8",
);
const jsonPlatformNotes = fs.readFileSync(
path.join(PYTHON_DIRECTORY, "snowflake.json"),
"utf8",
);
// Gather all versioning informationing to be available for import everywhere
const DOCSTRINGS = jsonDocstrings ? JSON.parse(jsonDocstrings) : {};
const VERSIONS_LIST = Object.keys(DOCSTRINGS).reverse();
const LATEST_VERSION = VERSIONS_LIST[0];
const DEFAULT_VERSION = "latest";
const PLATFORM_NOTES = jsonPlatformNotes ? JSON.parse(jsonPlatformNotes) : {};
let platformVersions = {};
let latestPlatformVersion = {};
for (const index in Object.keys(PLATFORM_NOTES)) {
const key = Object.keys(PLATFORM_NOTES)[index];
platformVersions[key] = Object.keys(PLATFORM_NOTES[key]);
latestPlatformVersion[key] = Object.keys(PLATFORM_NOTES[key]).at(-1);
}
const PLATFORM_VERSIONS = platformVersions;
const PLATFORM_LATEST_VERSIONS = latestPlatformVersion;
const PLATFORM_NAMES = {};
PLATFORM_NAMES["oss"] = "All versions";
PLATFORM_NAMES["sis"] = "Streamlit in Snowflake";
PLATFORM_NAMES["na"] = "Snowflake Native Apps";
const DEFAULT_PLATFORM = "oss";
const PROD_OPTIMIZATIONS = IS_DEV
? {}
: {
experimental: {
workerThreads: true,
cpus: 2,
sharedPool: true,
},
};
// IMPORTANT: Keep this in sync with netlify.toml
// prettier-ignore
const CSP_HEADER = [
"upgrade-insecure-requests;",
"frame-ancestors",
"'self'",
";",
"frame-src",
"https:",
";",
"connect-src",
"'self'",
"https://*.streamlit.app/",
"wss://*.streamlit.app/",
"https://streamlit.ghost.io/ghost/api/", // Blog API
"https://api.segment.io/", // Analytics
"https://cdn.segment.com/", // Analytics
"https://*.auryc.com/", // Analytics (Heap)
"https://www.google-analytics.com/", // Analytics
"https://stats.g.doubleclick.net/", // Analytics
"https://px.ads.linkedin.com/", // LinkedIn ad pixel
"https://*.algolia.net/", // Search
"https://*.algolianet.com/", // Search
"https://widget.kapa.ai/kapa-widget.bundle.js", // Kapa.ai
"https://kapa-widget-proxy-la7dkmplpq-uc.a.run.app/", // Kapa.ai
"https://www.google.com/recaptcha/api.js", // Recaptcha for Kapa.ai
"https://www.gstatic.com/recaptcha/releases/", // Recaptchas for Kapa.ai
"https://www.google.com/recaptcha/enterprise.js", // Recaptchas for Kapa.ai
";",
"default-src 'none';",
"font-src 'self';",
"form-action 'self';",
"img-src",
"'self'",
"data:",
"https:",
";",
"media-src",
"'self'",
"https://s3-us-west-2.amazonaws.com/assets.streamlit.io/", // Videos
";",
"script-src",
"'self'",
"'unsafe-inline'", // NextJS payload
"'unsafe-eval'", // Required for MDXRemote in [...slug].js. Using App Router may fix this.
"https://cdn.heapanalytics.com/", // Analytics
"https://cdn.segment.com/", // Analytics
"https://www.google-analytics.com/", // Analytics
"https://www.googletagmanager.com/", // Analytics
"https://identity.netlify.com/", // Netlify dev tools
"https://netlify-cdp-loader.netlify.app/netlify.js", // Netlify dev tools
"https://www.youtube.com/iframe_api/", // YouTube Embed
"https://snap.licdn.com/", // LinkedIn ad pixel
"https://connect.facebook.net/", // Facebook ad pixel
"https://*.algolia.net/", // Search
"https://*.algolianet.com/", // Search
"https://widget.kapa.ai/kapa-widget.bundle.js", // Kapa.ai
"https://kapa-widget-proxy-la7dkmplpq-uc.a.run.app/", // Kapa.ai
"https://www.google.com/recaptcha/api.js", // Recaptcha for Kapa.ai
"https://www.gstatic.com/recaptcha/releases/", // Recaptchas for Kapa.ai
"https://www.google.com/recaptcha/enterprise.js", // Recaptchas for Kapa.ai
";",
"style-src",
"'self'",
"'unsafe-inline'", // Twitter CSS
";",
"worker-src",
"'self'",
"blob:",
";",
];
module.exports = {
serverRuntimeConfig: {
DOCSTRINGS,
VERSIONS_LIST,
LATEST_VERSION,
DEFAULT_VERSION,
PLATFORM_NOTES,
PLATFORM_VERSIONS,
PLATFORM_LATEST_VERSIONS,
PLATFORM_NAMES,
DEFAULT_PLATFORM,
},
publicRuntimeConfig: {
VERSIONS_LIST,
LATEST_VERSION,
DEFAULT_VERSION,
PLATFORM_VERSIONS,
PLATFORM_LATEST_VERSIONS,
PLATFORM_NAMES,
DEFAULT_PLATFORM,
},
async rewrites() {
return [
{
source: "/sis/:path*",
destination: "/1.39.0/:path*",
},
{
source: `/${LATEST_VERSION}/:path*`,
destination: "/:path*",
},
{
source: `/latest/:path*`,
destination: "/:path*",
},
];
},
output: "export",
...PROD_OPTIMIZATIONS,
webpack: (configuration) => {
// Don't try to polyfill the fs module.
configuration.resolve.fallback = { fs: false };
configuration.module.rules.push(
{
test: /\.md$/,
use: "frontmatter-markdown-loader",
},
{
test: /\.svg$/,
use: ["@svgr/webpack", "file-loader"],
},
);
return configuration;
},
async exportPathMap(defaultPathMap) {
return {
...defaultPathMap,
};
},
// IMPORTANT: These headers are only useful in Dev,
// and are otherwise ignored by Netlify!
//
// On Netlify, use netlify.toml
//
// Please keep the two files in sync.
async headers() {
return [
{
source: "/(.*)",
headers: [
{
key: "Content-Security-Policy",
value: CSP_HEADER.join(" "),
},
{
key: "Strict-Transport-Security",
value: "max-age=31536000; includeSubDomains",
},
{
key: "X-Content-Type-Options",
value: "nosniff",
},
],
},
];
},
};