This project is a headless Shopify storefront built with Eleventy, a static site generator. It uses Decap CMS (formerly Netlify CMS) for content management and is configured for deployment on Netlify.
- Headless Shopify: Decouples the storefront from the Shopify backend.
- Eleventy: A flexible and fast static site generator.
- Decap CMS: For content management, integrated with GitHub for authentication.
- Netlify: For continuous deployment and hosting.
- GitHub OAuth: Secure authentication for Decap CMS.
- Node.js (v18 or higher)
- npm
- A Shopify account with a storefront.
- A GitHub account.
- A Netlify account.
-
Clone the repository:
git clone https://github.com/persephonepunch/headlessshopify.git cd headlessshopify -
Install dependencies:
npm install
-
Set up environment variables:
Create a
.envfile in the root of the project by copying the.env.examplefile:cp .env.example .env
You will need to populate this file with your own keys and IDs. See the "Configuration" sections below for more details.
This project is configured for continuous deployment on Netlify.
The netlify.toml file in the root of the project configures the build and deployment settings for Netlify:
[build]
publish = "public"
command = "npm run build"
functions = "functions"
# API redirects for functions
[[redirects]]
from = "/api/*"
to = "/.netlify/functions/:splat"
status = 200
force = truepublish = "public": Netlify will deploy thepublicdirectory.command = "npm run build": This command is run to build the site.functions = "functions": Serverless functions are located in thefunctionsdirectory.
When you push to the main branch of your GitHub repository, Netlify will automatically build and deploy the site.
For secure access to APIs and services, you need to set up environment variables in Netlify.
- Go to your site's dashboard on Netlify.
- Navigate to Site settings > Build & deploy > Environment.
- Add the following environment variables from your
.envfile:GITHUB_CLIENT_IDGITHUB_CLIENT_SECRETNETLIFY_SITE_IDSITE_URL- Any other sensitive keys your project requires.
This project uses Decap CMS for content management.
Authentication is handled via GitHub OAuth. Refer to the DECAP_OAUTH_SETUP.md file for detailed instructions on how to set up the GitHub OAuth app and configure Netlify.
The Decap CMS is configured in admin/config.yml:
backend:
name: github
repo: persephonepunch/headlessshopify
branch: mainThis configuration tells Decap CMS to use the main branch of the persephonepunch/headlessshopify repository on GitHub as the backend.
Once deployed, you can access the CMS at https://<your-site-url>/admin/. You will be prompted to log in with your GitHub account. Only users with write access to the repository will be able to authenticate.
The authentication flow for the CMS is as follows:
- A user navigates to
/admin/. - The user clicks "Login with GitHub".
- The user is redirected to GitHub to authorize the OAuth app.
- Upon successful authorization, GitHub redirects the user to a Netlify endpoint.
- Netlify handles the authentication and redirects the user back to the CMS, now authenticated.
The serverless functions in the /functions directory, such as oauth.js and github-callback.js, handle the server-side logic for the OAuth flow.
To run the project locally:
-
Install the Netlify CLI:
npm install -g netlify-cli
-
Run the development server:
netlify dev
This command will start a local server with a live preview and handle local OAuth authentication for the CMS.
-
Access the site and CMS:
- Site:
http://localhost:8888 - CMS:
http://localhost:8888/admin/
- Site:
/
├── admin/ # Decap CMS files
├── cms/ # Content files and templates for Eleventy
├── functions/ # Serverless functions for Netlify
├── theme/ # Eleventy theme files (layouts, partials, assets)
├── _utils/ # Eleventy utility functions (filters, shortcodes)
├── .eleventy.js # Eleventy configuration file
├── netlify.toml # Netlify configuration file
├── package.json # Project dependencies and scripts
└── README.md # This file