-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates to Hydrogen React API reference landing page (#874)
* Update Hydrogen React api landing page * Correct formatting
- Loading branch information
Showing
4 changed files
with
122 additions
and
40 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
packages/hydrogen-react/docs/staticPages/authenticate.client.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {createStorefrontClient} from '@shopify/hydrogen-react'; | ||
|
||
export const client = createStorefrontClient({ | ||
// load environment variables according to your framework and runtime | ||
storeDomain: process.env.PUBLIC_STORE_DOMAIN, | ||
storefrontApiVersion: process.env.PUBLIC_STOREFRONT_API_VERSION, | ||
publicStorefrontToken: process.env.PUBLIC_STOREFRONT_API_TOKEN, | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/hydrogen-react/docs/staticPages/authenticate.env.example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Replace with your own store domain and Storefront API token | ||
|
||
PUBLIC_STOREFRONT_API_TOKEN="public_token" | ||
PRIVATE_STOREFRONT_API_TOKEN="private_token" | ||
PUBLIC_STOREFRONT_API_VERSION="2023-04" | ||
PUBLIC_STORE_DOMAIN="store_id.myshopify.com" |
28 changes: 28 additions & 0 deletions
28
packages/hydrogen-react/docs/staticPages/authenticate.server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {client} from './client.js'; | ||
|
||
export async function getServerSideProps() { | ||
const response = await fetch(client.getStorefrontApiUrl(), { | ||
body: JSON.stringify({ | ||
query: GRAPHQL_QUERY, | ||
}), | ||
// Generate the headers using the private token. | ||
headers: client.getPrivateTokenHeaders(), | ||
method: 'POST', | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error(response.statusText); | ||
} | ||
|
||
const json = await response.json(); | ||
|
||
return {props: json}; | ||
} | ||
|
||
const GRAPHQL_QUERY = ` | ||
query { | ||
shop { | ||
name | ||
} | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters