Skip to content

Commit

Permalink
add error message for missing NEXT_PUBLIC_BASE_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchuman committed Feb 12, 2025
1 parent 08f3db6 commit 8c604fe
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 18 deletions.
10 changes: 5 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
NEXT_PUBLIC_BASE_URL="" #https://sanitypress.dev
NEXT_PUBLIC_BASE_URL="" # https://sanitypress.dev

NEXT_PUBLIC_SANITY_PROJECT_ID="" #abcdefgh
NEXT_PUBLIC_SANITY_DATASET="" #production
NEXT_PUBLIC_SANITY_PROJECT_ID="" # abcdefgh
NEXT_PUBLIC_SANITY_DATASET="" # production

SANITY_API_READ_TOKEN="" #"Viewer" token from https://sanity.io/manage
SANITY_API_READ_TOKEN="" # "Viewer" token from https://sanity.io/manage

NEXT_PUBLIC_GITHUB_TOKEN="" #recommended to add to display GitHub stars & forks
NEXT_PUBLIC_GITHUB_TOKEN="" # recommended to add to display GitHub stars & forks
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,18 @@ See the documentation if you are [having issues with the CLI](https://www.sanity

Alternatively, you can also clone or fork [the GitHub template](https://github.com/nuotsu/sanitypress) to set up manually.

### 2. Add content
### 2. Start local server

Run the following command to start the development server:

- Website: http://localhost:3000
- Sanity Studio: http://localhost:3000/admin

```sh
npm run dev
```

### 3. Add content

In your new Sanity Studio, publish the **required** `site` and `page` documents.

Expand All @@ -58,7 +69,7 @@ Alternatively, you can import the [demo site](https://demo.sanitypress.dev) data
sanity dataset import src/sanity/demo.tar.gz
```

### 3. Set up deployments
### 4. Set up deployments

#### 1. Create a GitHub repository

Expand Down Expand Up @@ -89,14 +100,10 @@ NEXT_PUBLIC_GITHUB_TOKEN="" # recommended to add to display GitHub stars & forks
- Vercel: [`vercel-dashboard-widget`](https://www.sanity.io/plugins/vercel-dashboard-widget)
- Netlify: [`sanity-plugin-dashboard-widget-netlify`](https://www.sanity.io/plugins/sanity-plugin-dashboard-widget-netlify)

### 4. Customize
### 5. Customize

Adjust frontend styles, edit/add Sanity schema and modules, and [more](https://sanitypress.dev/blog/the-developers-guide-to-customizing-sanitypress).

### 5. Inviting collaborators (Optional)

Invite team members via [Sanity Manage](https://www.sanity.io/manage) to collaborate on content in your Studio.

## Resources & Dependencies

- [_The Styled Heart_](https://sanitypress.dev/blog) — SanityPress Blog
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sanitypress",
"version": "6.2.14",
"version": "6.2.15",
"description": "An impressive Next.js + Sanity.io starter template",
"author": "nuotsu <[email protected]> (https://nuotsu.dev)",
"license": "ISC",
Expand Down
2 changes: 1 addition & 1 deletion src/app/(frontend)/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function getPost(params: { slug?: string }) {
})

if (!blogTemplateExists)
throw Error(
throw new Error(
'Missing blog template: 👻 Oof, your blog posts are ghosting...\n\n' +
'Solution: Add a new Global module document in your Sanity Studio with the path "blog/".\n' +
'Also add the Blog post content module to display blog post content.\n\n' +
Expand Down
2 changes: 1 addition & 1 deletion src/app/(frontend)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async function getPage() {
})

if (!page)
throw Error(
throw new Error(
"Missing homepage: 🏚️ There's no place like... index?\n\n" +
'Solution: Add a new Page document in your Sanity Studio with the slug "index".\n\n' +
'💁‍♂️ https://sanitypress.dev/docs/errors#missing-homepage',
Expand Down
8 changes: 8 additions & 0 deletions src/lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ export const dev = process.env.NODE_ENV === 'development'

export const vercelPreview = process.env.VERCEL_ENV === 'preview'

if (!process.env.NEXT_PUBLIC_BASE_URL) {
throw new Error(
'Missing base url: 🤞 Domain Expansion (Unlimited Void) requires a proper URL!\n\n' +
'Solution: Set your website URL as NEXT_PUBLIC_BASE_URL in your environment variables (including https://).\n\n' +
'💁‍♂️ https://sanitypress.dev/docs/errors#missing-base-url',
)
}

export const BASE_URL = dev
? 'http://localhost:3000'
: process.env.NEXT_PUBLIC_BASE_URL!
2 changes: 1 addition & 1 deletion src/sanity/lib/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function getSite() {
})

if (!site)
throw Error(
throw new Error(
'Missing Site settings: 🫠 Your website might be having an identity crisis...\n\n' +
'Solution: Publish the Site document in your Sanity Studio.\n\n' +
'💁‍♂️ https://sanitypress.dev/docs/errors#missing-site-settings',
Expand Down
2 changes: 1 addition & 1 deletion src/sanity/lib/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import 'server-only'
export const token = process.env.SANITY_API_READ_TOKEN

if (!token) {
throw Error('Missing SANITY_API_READ_TOKEN environment variable')
throw new Error('Missing SANITY_API_READ_TOKEN environment variable')
}
2 changes: 1 addition & 1 deletion src/ui/modules/SearchModule/SearchGoogle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function SearchGoogle({
}) {
const href = [
`https://www.google.com/search?q=${query} `,
`site:${process.env.NEXT_PUBLIC_BASE_URL?.replace(/https?:\/\//, '')}`,
`site:${process.env.NEXT_PUBLIC_BASE_URL}`,
scope === 'path' && path
? `/${path.replace(/\/?\*$/, '')}`
: scope === 'blog posts'
Expand Down

0 comments on commit 8c604fe

Please sign in to comment.