@zaneray/express-bigcommerce-middleware
v5.1.1
Published
Components for working with the BigCommerce API using Express and Node
Downloads
1,325
Maintainers
Keywords
Readme
ZaneRay BigCommerce Middleware package
Description
The ZaneRay Express BigCommerce Middleware package contains components for working with the BigCommerce API in a Node environment. There are 2 exported Components:
class BigCommerce - wraps the REST API for a single Big Commerce Storefront
BigCommerceRouter - ExpressJS router that provides standardized paths
caching - products and categories are going to get cached, /products and /categories The cache will be implemented in-memory and use session affinity to make sure a client browsing gets cached data
Running a stock express instance of the middleware
You can run a stock instance of the Express BigCommerce Middleware package by creating
an Express server, instantiating a BigCommerce instance, and placing the instance on app.locals.bigCommerce
as show below
const { BigCommerce, bigCommerceRouter } = require('@zaneray/express-bigcommerce-middleware');
const express = require("express");
const cookieParser = require('cookie-parser');
const bearerToken = require('express-bearer-token');
const expressip = require('express-ip');
const ExpressMiddleware = require('@zaneray/express-middleware');
const { get } = require('@zaneray/node-env');
const { logger } = require('@zaneray/gcp-node-logging');
const app = express();
const BC_CLIENT_ID = get('BC_CLIENT_ID');
const BC_ACCESS_TOKEN = get('BC_ACCESS_TOKEN');
const BC_STORE_HASH = get('BC_STORE_HASH');
const BC_CLIENT_SECRET = get('BC_CLIENT_SECRET');
const BC_CUSTOMER_TOKEN_APP_CLIENT_SECRET = get('BC_CUSTOMER_TOKEN_APP_CLIENT_SECRET');
app.locals.bigCommerce = new BigCommerce(BC_CLIENT_ID, BC_ACCESS_TOKEN, BC_STORE_HASH, BC_CLIENT_SECRET,BC_CUSTOMER_TOKEN_APP_CLIENT_SECRET);
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(bearerToken());
app.use(expressip().getIpInfoMiddleware);
app.use([bigCommerceRouter]);
//anything not handled is a 404
app.use(ExpressMiddleware.fourOfour);
// standard error handler
app.use(ExpressMiddleware.catchAllErrorHandler);
//setup express configuration
app.set("trust.proxy", true);
//setup serving the site root
const HOST = get('HOST','0.0.0.0');
const PORT = get('PORT',3000);
// have the server listen for requests
app.listen(PORT, HOST);
logger.debug("Server listening on " + HOST + ":" + PORT);