A middleware service for handling Shopify live preview functionality with Contentstack integration.
- Built with Fastify for high performance
- TypeScript support
- API documentation with Swagger
- CORS enabled
- Environment configuration
- Structured logging with pino
- Contentstack live preview integration
- Node.js (v20 or later)
- npm or yarn
- Contentstack account with API credentials
- Clone the repository:
git clone <repository-url>
cd live-preview-shopify-middleware- Install dependencies:
npm install
# or
yarn install- Create a
.envfile in the root directory with your Contentstack credentials:
# Server Configuration
PORT=3002
HOST=0.0.0.0
NODE_ENV=development
# Contentstack Configuration (Required)
CONTENTSTACK_DELIVERY_TOKEN=your_delivery_token_here
CONTENTSTACK_PREVIEW_TOKEN=your_preview_token_here
CONTENTSTACK_ENVIRONMENT=your_environment_here
CONTENTSTACK_API_KEY=your_api_key_here
CONTENTSTACK_PREVIEW_URL=https://api.contentstack.ioYou can copy the example file and modify it:
cp .env.example .envThe following environment variables are required for the middleware to function properly:
CONTENTSTACK_DELIVERY_TOKEN: Your Contentstack delivery tokenCONTENTSTACK_PREVIEW_TOKEN: Your Contentstack preview tokenCONTENTSTACK_ENVIRONMENT: Your Contentstack environment (e.g., 'development', 'production')CONTENTSTACK_API_KEY: Your Contentstack API key
CONTENTSTACK_PREVIEW_URL: Contentstack preview URL (defaults to 'https://api.contentstack.io')PORT: Server port (defaults to 3002)HOST: Server host (defaults to '0.0.0.0')NODE_ENV: Node environment (defaults to 'development')
To start the development server with hot-reload:
npm run dev
# or
yarn devTo build the project:
npm run build
# or
yarn buildTo start the production server:
npm start
# or
yarn startOnce the server is running, you can access the Swagger documentation at:
http://localhost:3002/documentation
This error occurs when the required Contentstack environment variables are not set. Make sure you have:
- Created a
.envfile with all required Contentstack credentials - Set the environment variables in your deployment environment
- Verified that the credentials are correct and have the necessary permissions
This error was resolved by updating the LivePreviewShopify class to properly handle configuration. Make sure you're using the latest version of the @contentstack/shopify-live-preview-sdk package.
npm run dev- Start development server with hot-reloadnpm run build- Build the projectnpm start- Start the production servernpm run test- Run testsnpm run lint- Run lintingnpm run format- Format code with Prettier
MIT