Skip to content

Commit

Permalink
fix: doc bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-landers committed Dec 9, 2020
1 parent db18d12 commit 9a6b56c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
24 changes: 14 additions & 10 deletions docs/previews/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ In this guide, we'll walk through how to configure a Next.js site for previews.

We're going to use Next with TypeScript for this example.

```
```bash
npx create-next-app previews
cd previews
rm -r ./pages/*
npm i @wpengine/headless @apollo/client graphql
npm i typescript @types/react @types/react-dom @types/node -D
npm i @wpengine/headless
```

TL;DR
Expand Down Expand Up @@ -41,7 +43,7 @@ The `@wpengine/headless` package provides helpers to get previews working in a R

Install the npm package via:

```
```bash
npm i @wpengine/headless
```

Expand All @@ -66,15 +68,17 @@ The framework provides a Node.js auth handler to do the exchange for you.

In order to support the exchange of the access code for an access token, the framework provides a Node authorization handler:

```
```typescript
import { authorizeHandler } from '@wpengine/headless';
```

`authorizeHandler` accepts a Node request (IncomingMessage) and response (ServerResponse) which are compatible with ExpressJS, Next APIs, etc.

In order to enable the handler in Next, create a new API route `/pages/api/authorize.ts` and add:
In order to enable the handler in Next, create a new API route:

```
`/pages/api/authorize.ts`

```typescript
import { authorizeHandler } from '@wpengine/headless';

export default authorizeHandler;
Expand Down Expand Up @@ -208,22 +212,22 @@ export default function Posts() {
We need to let the frontend know about our WordPress instance. The framework expects a few environment variables with this information. Create a file in the root of the project `/.env.local`.
```
```bash
# Base URL for WordPress
NEXT_PUBLIC_WORDPRESS_URL=http://developer-hub.local
NEXT_PUBLIC_WORDPRESS_URL=http://yourwp.com

# Plugin secret found in WordPress Settings->Headless
WPE_HEADLESS_SECRET=YOUR_PLUGIN_SECRET

# Location of the auth handler endpoint
NEXT_PUBLIC_AUTH_ENDPOINT=/api/authorize
NEXT_PUBLIC_AUTHORIZATION_URL=/api/authorize
```
## Try it out!
You can run the project via:
```
```bash
npm run dev
```
Expand Down
4 changes: 2 additions & 2 deletions examples/preview/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Install the latest plugin for this project and [WPGraphQL](https://wordpress.org

The framework expects a few environment variables. Create a file in the root of the example project `/.env.local`.

```
```bash
# Base URL for WordPress
NEXT_PUBLIC_WORDPRESS_URL=http://yourwpsite.com

Expand All @@ -23,7 +23,7 @@ WPE_HEADLESS_SECRET=YOUR_PLUGIN_SECRET

## Run it

```
```bash
npm i
npm run dev
```
Expand Down

0 comments on commit 9a6b56c

Please sign in to comment.