Skip to content

Commit

Permalink
Fix NEXT_PUBLIC_ environment variables in cache
Browse files Browse the repository at this point in the history
- Use dynamic lookup for `NEXT_PUBLIC_VERCEL_URL` to avoid inlining
- Add `NEXT_PUBLIC_SANITY_*` to Turborepo `pipeline.build.env` cache key
  • Loading branch information
taesungh committed Jan 20, 2024
1 parent 63697be commit 469caa3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion apps/site/src/lib/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import axios from "axios";
import { cookies } from "next/headers";

const LOCAL_API_URL = "http://localhost:8000";
const SERVER_HOST = process.env.NEXT_PUBLIC_VERCEL_URL;
// Important: we need to do a dynamic lookup since otherwise the environment variable
// will be inlined during build and cause faulty caching issues (see #290)
const varName = "NEXT_PUBLIC_VERCEL_URL";
const SERVER_HOST = process.env[varName];

// The Vercel Serverless Function for the API lives outside the scope of Next.js
// so the publicly deployed URL must be used instead of a rewrite
Expand Down
1 change: 1 addition & 0 deletions apps/site/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": ["//"],
"pipeline": {
"build": {
"env": ["NEXT_PUBLIC_SANITY_*"],
"inputs": [
"src/**",
"public/**",
Expand Down

0 comments on commit 469caa3

Please sign in to comment.