42
loading...
This website collects cookies to deliver better user experience
.astro
files work!.env
file (no matter which project you cloned), and populate it with the key and endpoint you got from Shopify:SHOPIFY_STOREFRONT_API_TOKEN=example
SHOPIFY_API_ENDPOINT=https://exampleshopify/graphql.json
npm start
! You might have to change some copy, but ** you’re all done**. Woo hoo! Go forth and customize it!snowpack.config.mjs
to make your serverless functions work.mjs
file. That’s because it uses the ECMAScript module system, which you can research on your own if it interests you.export default {
env: {
NETLIFY_URL: process.env.NETLIFY
? process.env.URL
: 'http://localhost:8888',
},
};
import.meta.env
.src/pages/
folder. Astro uses page-based routing, so by making these files, the routes automatically exist! I named them as:index.astro
– The homepage!cart.astro
– The cart page!$product.astro
– The template page that defines each product! When a page file starts with $
in Astro, that means it’s a collection page type, which you use to generate multiple pages from a single template.index
and cart
pages, you can use Astro’s various data fetching options. For example, if you want to query the get-product-list
endpoint, your fetch might look like this:let products = await fetch(`${import.meta.env.NETLIFY_URL}/.netlify/functions/get-product-list`)
.then(res => res.json()).then((response) => {
return response.products.edges
});
$product
page, except you’ll use Astro’s Collections API to create routes for each of your product pages!