Skip to content

Commit

Permalink
Add new import flow to CMS examples (vercel#14053)
Browse files Browse the repository at this point in the history
[ch2502]

- Added new import flow to every CMS example, using the deploy button, and removed `vercel.json`
- Replaced `dotenv` with the new env support in outdated examples
  • Loading branch information
lfades authored and rokinsky committed Jul 11, 2020
1 parent cc84163 commit 4854a42
Show file tree
Hide file tree
Showing 79 changed files with 338 additions and 654 deletions.
6 changes: 6 additions & 0 deletions examples/blog-starter-typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ To create the blog posts we use [`remark`](https://github.com/remarkjs/remark) a

## How to use

## Deploy your own

Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/git?s=https://github.com/vercel/next.js/tree/canary/examples/blog-starter-typescript)

### Using `create-next-app`

Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:
Expand Down
1 change: 0 additions & 1 deletion examples/blog-starter-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"@types/node": "^14.0.1",
"@types/react": "^16.9.35",
"@types/react-dom": "^16.9.8",
"dotenv": "8.2.0",
"postcss-preset-env": "^6.7.0",
"tailwindcss": "^1.4.0"
}
Expand Down
6 changes: 6 additions & 0 deletions examples/blog-starter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ To create the blog posts we use [`remark`](https://github.com/remarkjs/remark) a

[https://next-blog-starter.now.sh/](https://next-blog-starter.now.sh/)

## Deploy your own

Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/git?s=https://github.com/vercel/next.js/tree/canary/examples/blog-starter)

### Related examples

- [WordPress](/examples/cms-wordpress)
Expand Down
1 change: 0 additions & 1 deletion examples/blog-starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"remark-html": "10.0.0"
},
"devDependencies": {
"dotenv": "8.2.0",
"postcss-preset-env": "^6.7.0",
"tailwindcss": "^1.4.0"
}
Expand Down
8 changes: 4 additions & 4 deletions examples/cms-agilitycms/.env.local.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NEXT_EXAMPLE_CMS_AGILITY_GUID=
NEXT_EXAMPLE_CMS_AGILITY_API_FETCH_KEY=
NEXT_EXAMPLE_CMS_AGILITY_API_PREVIEW_KEY=
NEXT_EXAMPLE_CMS_AGILITY_SECURITY_KEY=
AGILITY_CMS_GUID=
AGILITY_CMS_API_FETCH_KEY=
AGILITY_CMS_API_PREVIEW_KEY=
AGILITY_CMS_SECURITY_KEY=
41 changes: 23 additions & 18 deletions examples/cms-agilitycms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ This example showcases Next.js's [Static Generation](https://nextjs.org/docs/bas
- **Live**: [https://next-blog-agilitycms.now.sh/](https://next-blog-agilitycms.now.sh/)
- **Preview Mode**: [https://next-blog-agilitycms.now.sh/?agilitypreviewkey=...](https://next-blog-agilitycms.now.sh/?agilitypreviewkey=GzL%2fio1pLkfKc9BR1%2fC1cDQeKjL0AkwrTAJ22q3UEjAcOhyrqZejDkDv4kMlBKqrEuQxsuRyiP%2bUaykDYlJ%2fJg%3d%3d)

## Deploy your own

Once you have access to [the environment variables you'll need](#step-15-set-up-environment-variables), deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/git?s=https://github.com/vercel/next.js/tree/canary/examples/cms-agilitycms&env=AGILITY_CMS_GUID,AGILITY_CMS_API_FETCH_KEY,AGILITY_CMS_API_PREVIEW_KEY,AGILITY_CMS_SECURITY_KEY&envDescription=API%20Keys%20required%20by%20Agility%20CMS.%20More%20details%20on%20https://vercel.link/agility-cms-env)

### Related examples

- [WordPress](/examples/cms-wordpress)
Expand Down Expand Up @@ -263,18 +269,18 @@ Go to the **Getting Started** section from the menu and click on **API Keys**. Y

Then set each variable on `.env.local`:

- `NEXT_EXAMPLE_CMS_AGILITY_GUID` should be the **Instance GUID** field
- `NEXT_EXAMPLE_CMS_AGILITY_API_FETCH_KEY` should be the **Live API Key** field
- `NEXT_EXAMPLE_CMS_AGILITY_API_PREVIEW_KEY` should be the **Preview API Key** field - this is used when the site is in [Preview Mode](https://nextjs.org/docs/advanced-features/preview-mode) and allows your site to pull the latest content, regardless of whether it is published or not.
- `NEXT_EXAMPLE_CMS_AGILITY_SECURITY_KEY` should be the **Security Key** field that can be found in **Settings** > **Global Security** - this is used to communicate between the CMS and your site to validate [Preview Mode](https://nextjs.org/docs/advanced-features/preview-mode)
- `AGILITY_CMS_GUID` should be the **Instance GUID** field
- `AGILITY_CMS_API_FETCH_KEY` should be the **Live API Key** field
- `AGILITY_CMS_API_PREVIEW_KEY` should be the **Preview API Key** field - this is used when the site is in [Preview Mode](https://nextjs.org/docs/advanced-features/preview-mode) and allows your site to pull the latest content, regardless of whether it is published or not.
- `AGILITY_CMS_SECURITY_KEY` should be the **Security Key** field that can be found in **Settings** > **Global Security** - this is used to communicate between the CMS and your site to validate [Preview Mode](https://nextjs.org/docs/advanced-features/preview-mode)

Your `.env.local` file should look like this:

```bash
NEXT_EXAMPLE_CMS_AGILITY_GUID=...
NEXT_EXAMPLE_CMS_AGILITY_API_FETCH_KEY=...
NEXT_EXAMPLE_CMS_AGILITY_API_PREVIEW_KEY=...
NEXT_EXAMPLE_CMS_AGILITY_SECURITY_KEY=...
AGILITY_CMS_GUID=...
AGILITY_CMS_API_FETCH_KEY=...
AGILITY_CMS_API_PREVIEW_KEY=...
AGILITY_CMS_SECURITY_KEY=...
```

### Step 16. Run Next.js in development mode
Expand All @@ -293,20 +299,19 @@ Your blog should be up and running on [http://localhost:3000](http://localhost:3

### Step 17. Deploy on Vercel

You can deploy this app to the cloud with [Vercel](https://vercel.com/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
You can deploy this app to the cloud with [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).

To deploy on Vercel, you need to set the environment variables using the [Vercel CLI](https://vercel.com/download) ([Documentation](https://vercel.com/docs/now-cli#commands/secrets)).
#### Deploy Your Local Project

Install [Vercel CLI](https://vercel.com/download), log in to your account from the CLI, and run the following commands to add the environment variables. Replace each variable with the corresponding strings in `.env.local`:
To deploy your local project to Vercel, push it to GitHub/GitLab/Bitbucket and [import to Vercel](https://vercel.com/import/git?utm_source=github&utm_medium=readme&utm_campaign=next-example).

```
vercel secrets add next_example_cms_agility_guid <NEXT_EXAMPLE_CMS_AGILITY_GUID>
vercel secrets add next_example_cms_agility_api_fetch_key <NEXT_EXAMPLE_CMS_AGILITY_API_FETCH_KEY>
vercel secrets add next_example_cms_agility_api_preview_key <NEXT_EXAMPLE_CMS_AGILITY_API_PREVIEW_KEY>
vercel secrets add next_example_cms_agility_security_key <NEXT_EXAMPLE_CMS_AGILITY_SECURITY_KEY>
```
**Important**: When you import your project on Vercel, make sure to click on **Environment Variables** and set them to match your `.env.local` file.

#### Deploy from Our Template

Alternatively, you can deploy using our template by clicking on the Deploy button below.

Then push the project to GitHub/GitLab/Bitbucket and [import to Vercel](https://vercel.com/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) to deploy.
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/git?s=https://github.com/vercel/next.js/tree/canary/examples/cms-agilitycms&env=AGILITY_CMS_GUID,AGILITY_CMS_API_FETCH_KEY,AGILITY_CMS_API_PREVIEW_KEY,AGILITY_CMS_SECURITY_KEY&envDescription=API%20Keys%20required%20by%20Agility%20CMS.%20More%20details%20on%20https://vercel.link/agility-cms-env)

### Step 18. Try preview mode

Expand Down
8 changes: 4 additions & 4 deletions examples/cms-agilitycms/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { requireComponentDependancyByName } from './dependancies'

// Our LIVE API client
const liveClient = agility.getApi({
guid: process.env.NEXT_EXAMPLE_CMS_AGILITY_GUID,
apiKey: process.env.NEXT_EXAMPLE_CMS_AGILITY_API_FETCH_KEY,
guid: process.env.AGILITY_CMS_GUID,
apiKey: process.env.AGILITY_CMS_API_FETCH_KEY,
})

// Our PREVIEW API client
const previewClient = agility.getApi({
guid: process.env.NEXT_EXAMPLE_CMS_AGILITY_GUID,
apiKey: process.env.NEXT_EXAMPLE_CMS_AGILITY_API_PREVIEW_KEY,
guid: process.env.AGILITY_CMS_GUID,
apiKey: process.env.AGILITY_CMS_API_PREVIEW_KEY,
isPreview: true,
})

Expand Down
2 changes: 1 addition & 1 deletion examples/cms-agilitycms/lib/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export async function validateSlugForPreview({ slug, contentID }) {
//Generates a preview key to compare agains
export function generatePreviewKey() {
//the string we want to encode
const str = `-1_${process.env.NEXT_EXAMPLE_CMS_AGILITY_SECURITY_KEY}_Preview`
const str = `-1_${process.env.AGILITY_CMS_SECURITY_KEY}_Preview`

//build our byte array
let data = []
Expand Down
16 changes: 0 additions & 16 deletions examples/cms-agilitycms/vercel.json

This file was deleted.

4 changes: 2 additions & 2 deletions examples/cms-buttercms/.env.local.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Copy this file as .env.local
NEXT_EXAMPLE_CMS_BUTTERCMS_API_KEY=
NEXT_EXAMPLE_CMS_BUTTERCMS_PREVIEW_SECRET=
BUTTERCMS_API_KEY=
BUTTERCMS_PREVIEW_SECRET=
29 changes: 18 additions & 11 deletions examples/cms-buttercms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ This example showcases Next.js's [Static Generation](https://nextjs.org/docs/bas

[https://next-blog-buttercms.now.sh/](https://next-blog-buttercms.now.sh/)

## Deploy your own

Once you have access to [the environment variables you'll need](#step-2-set-up-environment-variables), deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/git?s=https://github.com/vercel/next.js/tree/canary/examples/cms-buttercms&env=BUTTERCMS_API_KEY,BUTTERCMS_PREVIEW_SECRET&envDescription=Required%20to%20connect%20the%20app%20with%20ButterCMS.%20More%20details%20on%20https://vercel.link/buttercms-env)

### Related examples

- [WordPress](/examples/cms-wordpress)
Expand Down Expand Up @@ -59,8 +65,8 @@ cp .env.local.example .env.local

Then set each variable on `.env.local`:

- `NEXT_EXAMPLE_CMS_BUTTERCMS_API_KEY` should be set as the API key.
- `NEXT_EXAMPLE_CMS_BUTTERCMS_PREVIEW_SECRET` can be any random string (but avoid spaces), like `MY_SECRET` - this is used for [Preview Mode](https://nextjs.org/docs/advanced-features/preview-mode).
- `BUTTERCMS_API_KEY` should be set as the API key.
- `BUTTERCMS_PREVIEW_SECRET` can be any random string (but avoid spaces), like `MY_SECRET` - this is used for [Preview Mode](https://nextjs.org/docs/advanced-features/preview-mode).

### Step 3. Run Next.js in development mode

Expand Down Expand Up @@ -96,23 +102,24 @@ To enable the Preview Mode, go to this URL:
http://localhost:3000/api/preview?secret=<secret>&slug=draft-post-test
```

- `<secret>` should be the string you entered for `NEXT_EXAMPLE_CMS_BUTTERCMS_PREVIEW_SECRET`.
- `<secret>` should be the string you entered for `BUTTERCMS_PREVIEW_SECRET`.

You should now be able to see the draft post. To exit the preview mode, you can click **Click here to exit preview mode** at the top.

**Tip**: [You can set the preview URL on ButterCMS](https://buttercms.com/kb/preview-urls).

### Step 5. Deploy on Vercel

You can deploy this app to the cloud with [Vercel](https://vercel.com/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
You can deploy this app to the cloud with [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).

To deploy on Vercel, you need to set the environment variables with **Vercel Secrets** using [Vercel CLI](https://vercel.com/download) ([Documentation](https://vercel.com/docs/vercel-cli#commands/secrets)).
#### Deploy Your Local Project

Install [Vercel CLI](https://vercel.com/download), log in to your account from the CLI, and run the following commands to add the environment variables. Replace `<NEXT_EXAMPLE_CMS_BUTTERCMS_API_KEY>` and `<NEXT_EXAMPLE_CMS_BUTTERCMS_PREVIEW_SECRET>` with the corresponding strings in `.env`.
To deploy your local project to Vercel, push it to GitHub/GitLab/Bitbucket and [import to Vercel](https://vercel.com/import/git?utm_source=github&utm_medium=readme&utm_campaign=next-example).

```
vercel secrets add next_example_cms_buttercms_api_key <NEXT_EXAMPLE_CMS_BUTTERCMS_API_KEY>
vercel secrets add next_example_cms_buttercms_preview_secret <NEXT_EXAMPLE_CMS_BUTTERCMS_PREVIEW_SECRET>
```
**Important**: When you import your project on Vercel, make sure to click on **Environment Variables** and set them to match your `.env.local` file.

#### Deploy from Our Template

Alternatively, you can deploy using our template by clicking on the Deploy button below.

Then push the project to GitHub/GitLab/Bitbucket and [import to Vercel](https://vercel.com/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) to deploy.
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/git?s=https://github.com/vercel/next.js/tree/canary/examples/cms-buttercms&env=BUTTERCMS_API_KEY,BUTTERCMS_PREVIEW_SECRET&envDescription=Required%20to%20connect%20the%20app%20with%20ButterCMS.%20More%20details%20on%20https://vercel.link/buttercms-env)
2 changes: 1 addition & 1 deletion examples/cms-buttercms/lib/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Butter from 'buttercms'
const butter = Butter(process.env.NEXT_EXAMPLE_CMS_BUTTERCMS_API_KEY)
const butter = Butter(process.env.BUTTERCMS_API_KEY)

export async function getPreviewPostBySlug(slug) {
const postResponse = await butter.post.retrieve(slug, {
Expand Down
3 changes: 1 addition & 2 deletions examples/cms-buttercms/pages/api/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ export default async function preview(req, res) {
// Check the secret and next parameters
// This secret should only be known to this API route and the CMS
if (
req.query.secret !==
process.env.NEXT_EXAMPLE_CMS_BUTTERCMS_PREVIEW_SECRET ||
req.query.secret !== process.env.BUTTERCMS_PREVIEW_SECRET ||
!req.query.slug
) {
return res.status(401).json({ message: 'Invalid token' })
Expand Down
11 changes: 0 additions & 11 deletions examples/cms-buttercms/vercel.json

This file was deleted.

4 changes: 0 additions & 4 deletions examples/cms-contentful/.env.example

This file was deleted.

4 changes: 4 additions & 0 deletions examples/cms-contentful/.env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CONTENTFUL_SPACE_ID=
CONTENTFUL_ACCESS_TOKEN=
CONTENTFUL_PREVIEW_ACCESS_TOKEN=
CONTENTFUL_PREVIEW_SECRET=
34 changes: 0 additions & 34 deletions examples/cms-contentful/.gitignore

This file was deleted.

Loading

0 comments on commit 4854a42

Please sign in to comment.