Skip to content

Commit

Permalink
Merge pull request #31 from Exygy/sanity-environment
Browse files Browse the repository at this point in the history
add sanity config to support viewing drafts for staging
  • Loading branch information
kramduckner authored Jun 11, 2024
2 parents 686c4b2 + fa7226a commit a8718b7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ interface Config {
UCSF_DOMAIN: string;
SANITY_PROJECT_ID: string;
SANITY_PROJECT_DATASET: string;
SANITY_USE_CDN: boolean;
SANITY_PERSPECTIVE: "raw" | "published" | "previewDrafts";
SANITY_API_TOKEN: string;
SANITY_WITH_CREDENTIALS: boolean;
}

const config: Config = {
Expand All @@ -46,6 +50,10 @@ const config: Config = {
UCSF_DOMAIN: "dcnav",
SANITY_PROJECT_ID: CONFIG.SANITY_PROJECT_ID,
SANITY_PROJECT_DATASET: CONFIG.SANITY_PROJECT_DATASET,
SANITY_USE_CDN: CONFIG.SANITY_USE_CDN,
SANITY_PERSPECTIVE: CONFIG.SANITY_PERSPECTIVE,
SANITY_WITH_CREDENTIALS: CONFIG.SANITY_WITH_CREDENTIALS,
SANITY_API_TOKEN: CONFIG.SANITY_API_TOKEN,
};

if (CONFIG.TESTCAFE_RUNNING) {
Expand Down
5 changes: 4 additions & 1 deletion app/sanity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ const todaysDate = new Date().toISOString().slice(0, 10); // YYYY-MM-DD
const sanityConfig: ClientConfig = {
projectId: appConfig.SANITY_PROJECT_ID,
dataset: appConfig.SANITY_PROJECT_DATASET,
useCdn: true, // set to `false` to bypass the edge cache
useCdn: appConfig.SANITY_USE_CDN,
perspective: appConfig.SANITY_PERSPECTIVE,
token: appConfig.SANITY_API_TOKEN,
withCredentials: appConfig.SANITY_WITH_CREDENTIALS,
apiVersion: todaysDate, // use current date (YYYY-MM-DD) to target the latest API version
};
const client = createClient(sanityConfig);
Expand Down
6 changes: 6 additions & 0 deletions config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ AUTH0_REDIRECT_URI: "http://localhost:8080/auth"
# Get Project ID in Sanity Studio
SANITY_PROJECT_ID:
SANITY_PROJECT_DATASET: "development"
# Disable cdn to omit caching
SANITY_USE_CDN: false
SANITY_PERSPECTIVE: "published"
# Need a token for things like previewing drafts
SANITY_WITH_CREDENTIALS: false
SANITY_API_TOKEN: "<SANITY_API_KEY>"
6 changes: 6 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ const environmentConfig = [
"AUTH0_CLIENT_ID",
"AUTH0_DOMAIN",
"AUTH0_REDIRECT_URI",
"SANITY_PROJECT_ID",
"SANITY_PROJECT_DATASET",
"SANITY_USE_CDN",
"SANITY_PERSPECTIVE",
"SANITY_WITH_CREDENTIALS",
"SANITY_API_TOKEN",
];

const config = environmentConfig.reduce((acc, key) => {
Expand Down

0 comments on commit a8718b7

Please sign in to comment.