Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

chore(www): static assets cdn (#33344)

Alaister Young199223065c56
diff --git a/apps/studio/package.json b/apps/studio/package.json
index 1407ff15e56..56c4a4022c9 100644
--- a/apps/studio/package.json
+++ b/apps/studio/package.json
@@ -6,7 +6,7 @@
"preinstall": "npx only-allow pnpm",
"dev": "next dev -p 8082",
"dev:secrets:pull": "AWS_PROFILE=supabase-dev node ../../scripts/getSecrets.js -n local/studio",
- "build": "next build",
+ "build": "next build && ./../../scripts/upload-static-assets.sh",
"start": "next start",
"lint": "next lint",
"clean": "rimraf node_modules tsconfig.tsbuildinfo .next .turbo",
diff --git a/apps/studio/vercel.json b/apps/studio/vercel.json
index e2a5e6299e9..8df7e53755b 100644
--- a/apps/studio/vercel.json
+++ b/apps/studio/vercel.json
@@ -1,3 +1,3 @@
{
- "buildCommand": "next build && ./../../scripts/upload-static-assets.sh"
+ "buildCommand": "pnpm build"
}
diff --git a/apps/www/next.config.mjs b/apps/www/next.config.mjs
index 106354d8542..60ab32247b9 100644
--- a/apps/www/next.config.mjs
+++ b/apps/www/next.config.mjs
@@ -42,6 +42,7 @@ const withBundleAnalyzer = bundleAnalyzer({
*/
const nextConfig = {
basePath: '',
+ assetPrefix: getAssetPrefix(),
pageExtensions: ['js', 'jsx', 'ts', 'tsx', 'md', 'mdx'],
trailingSlash: false,
transpilePackages: ['ui', 'ui-patterns', 'common', 'shared-data', 'icons', 'api-types'],
@@ -103,3 +104,22 @@ export default () => {
const plugins = [withContentlayer, withMDX, withBundleAnalyzer]
return plugins.reduce((acc, next) => next(acc), nextConfig)
}
+
+const SUPABASE_ASSETS_URL =
+ process.env.NEXT_PUBLIC_ENVIRONMENT === 'staging'
+ ? 'https://frontend-assets.supabase.green'
+ : 'https://frontend-assets.supabase.com'
+
+function getAssetPrefix() {
+ // If not force enabled, but not production env, disable CDN
+ if (process.env.FORCE_ASSET_CDN !== '1' && process.env.VERCEL_ENV !== 'production') {
+ return undefined
+ }
+
+ // Force disable CDN
+ if (process.env.FORCE_ASSET_CDN === '-1') {
+ return undefined
+ }
+
+ return `${SUPABASE_ASSETS_URL}/${process.env.SITE_NAME}/${process.env.VERCEL_GIT_COMMIT_SHA.substring(0, 12)}`
+}
diff --git a/apps/www/package.json b/apps/www/package.json
index 57ab710fe05..3ccc865b5c0 100644
--- a/apps/www/package.json
+++ b/apps/www/package.json
@@ -14,7 +14,7 @@
"typecheck": "pnpm run content:build && tsc --noEmit",
"content:build": "contentlayer2 build && node scripts/generateStaticContent.mjs",
"prettier": "prettier --write \"./{pages,components,lib,stores,styles,tests}/**/*.{ts,tsx,md,js,jsx,json}\"",
- "postbuild": "node ./internals/generate-sitemap.mjs"
+ "postbuild": "node ./internals/generate-sitemap.mjs && ./../../scripts/upload-static-assets.sh"
},
"dependencies": {
"@code-hike/mdx": "^0.9.0",
diff --git a/apps/www/vercel.json b/apps/www/vercel.json
new file mode 100644
index 00000000000..8df7e53755b
--- /dev/null
+++ b/apps/www/vercel.json
@@ -0,0 +1,3 @@
+{
+ "buildCommand": "pnpm build"
+}
diff --git a/turbo.json b/turbo.json
index 9073806fcfe..f4aca92dcae 100644
--- a/turbo.json
+++ b/turbo.json
@@ -110,7 +110,12 @@
"HUBSPOT_ENTERPRISE_FORM_GUID",
"OPENAI_API_KEY",
"EMAIL_REPORT_SLACK_WEBHOOK",
- "npm_lifecycle_event"
+ "npm_lifecycle_event",
+ "AWS_ACCESS_KEY_ID",
+ "AWS_SECRET_ACCESS_KEY",
+ "FORCE_ASSET_CDN",
+ "ASSET_CDN_S3_ENDPOINT",
+ "SITE_NAME"
],
"outputs": [".next/**", "!.next/cache/**", ".contentlayer/**"]
},