Skip to content

Commit f255627

Browse files
authored
chore(docs): static assets cdn (supabase#33347)
* chore(docs): static assets cdn * r2 env vars * embed asset url directly
1 parent 783b715 commit f255627

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

apps/docs/next.config.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const withMDX = nextMdx({
3636
/** @type {import('next').NextConfig} nextConfig */
3737

3838
const nextConfig = {
39+
assetPrefix: getAssetPrefix(),
3940
// Append the default value with md extensions
4041
pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
4142
// reactStrictMode: true,
@@ -171,3 +172,18 @@ const configExport = () => {
171172
}
172173

173174
export default configExport
175+
176+
function getAssetPrefix() {
177+
// If not force enabled, but not production env, disable CDN
178+
if (process.env.FORCE_ASSET_CDN !== '1' && process.env.VERCEL_ENV !== 'production') {
179+
return undefined
180+
}
181+
182+
// Force disable CDN
183+
if (process.env.FORCE_ASSET_CDN === '-1') {
184+
return undefined
185+
}
186+
187+
// @ts-ignore
188+
return `https://frontend-assets.supabase.com/${process.env.SITE_NAME}/${process.env.VERCEL_GIT_COMMIT_SHA.substring(0, 12)}`
189+
}

apps/docs/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
"dev": "concurrently --kill-others \"next dev --port 3001\" \"pnpm run dev:watch:troubleshooting\"",
99
"dev:watch:troubleshooting": "node ./scripts/troubleshooting/watch.mjs",
1010
"dev:secrets:pull": "AWS_PROFILE=supabase-dev node ../../scripts/getSecrets.js -n local/docs",
11+
"prebuild": "pnpm run codegen:references && pnpm run codegen:examples",
1112
"build": "next build",
1213
"build:analyze": "ANALYZE=true next build",
1314
"build:sitemap": "tsx ./internals/generate-sitemap.ts",
14-
"postbuild": "pnpm run build:sitemap",
15+
"postbuild": "pnpm run build:sitemap && ./../../scripts/upload-static-assets.sh",
1516
"start": "next start",
1617
"lint": "next lint",
1718
"lint:mdx": "supa-mdx-lint content --config ../../supa-mdx-lint.config.toml",

apps/docs/turbo.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@
4040
"DOCS_REVALIDATION_KEYS",
4141
"DOCS_REVALIDATION_OVERRIDE_KEYS",
4242
"SUPABASE_SECRET_KEY",
43-
"OPENAI_API_KEY"
43+
"OPENAI_API_KEY",
44+
"AWS_ACCESS_KEY_ID",
45+
"AWS_SECRET_ACCESS_KEY",
46+
"FORCE_ASSET_CDN",
47+
"ASSET_CDN_S3_ENDPOINT",
48+
"SITE_NAME"
4449
],
4550
"inputs": ["$TURBO_DEFAULT$"],
4651
"outputs": [".next/**", "!.next/cache/**"]

apps/docs/vercel.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"buildCommand": "pnpm build"
3+
}

0 commit comments

Comments
 (0)