Skip to content

Commit

Permalink
fix: add vercel native env variables as fallback (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmelve authored Sep 8, 2023
1 parent 06bf67d commit 5ccfd6a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
13 changes: 10 additions & 3 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
import { loadEnv } from "vite";
const {
PUBLIC_SANITY_STUDIO_PROJECT_ID,
PUBLIC_SANITY_STUDIO_DATASET
PUBLIC_SANITY_STUDIO_DATASET,
PUBLIC_SANITY_PROJECT_ID,
PUBLIC_SANITY_DATASET,
} = loadEnv(import.meta.env.MODE, process.cwd(), "");
import { defineConfig } from "astro/config";

// Different environments use different variables
const projectId = PUBLIC_SANITY_STUDIO_PROJECT_ID || PUBLIC_SANITY_PROJECT_ID;
const dataset = PUBLIC_SANITY_STUDIO_DATASET || PUBLIC_SANITY_DATASET;

import sanity from "@sanity/astro";
import react from "@astrojs/react";

Expand All @@ -19,8 +26,8 @@ export default defineConfig({
output: "hybrid",
adapter: vercel(),
integrations: [sanity({
projectId: PUBLIC_SANITY_STUDIO_PROJECT_ID,
dataset: PUBLIC_SANITY_STUDIO_DATASET,
projectId,
dataset,
studioBasePath: "/admin",
useCdn: false,
// `false` if you want to ensure fresh data
Expand Down
9 changes: 7 additions & 2 deletions sanity.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
const projectId = import.meta.env.PUBLIC_SANITY_STUDIO_PROJECT_ID!;
const dataset = import.meta.env.PUBLIC_SANITY_STUDIO_DATASET!;
// Different environments use different variables
const projectId =
import.meta.env.PUBLIC_SANITY_STUDIO_PROJECT_ID! ||
import.meta.env.PUBLIC_SANITY_PROJECT_ID!;
const dataset =
import.meta.env.PUBLIC_SANITY_STUDIO_DATASET! ||
import.meta.env.PUBLIC_SANITY_DATASET!;

// Feel free to remove this check if you don't need it
if (!projectId || !dataset) {
Expand Down

1 comment on commit 5ccfd6a

@vercel
Copy link

@vercel vercel bot commented on 5ccfd6a Sep 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

template-astro-clean – ./

template-astro-clean-git-main.sanity.build
template-astro-clean.sanity.build

Please sign in to comment.