This sample demonstrates using Mongoose to build an eCommerce shopping cart using Netlify Functions, which runs on AWS Lambda.
Other tools include:
Make sure you have a local stargate instance running as described on the main page of this repo.
- Copy the
.env.example
file to.env
and fill in the values for the environment variables. - Set
IS_ASTRA
totrue
- Set
ASTRA_DB_ID
to your AstraDB database ID - Set
ASTRA_DB_REGION
to your AstraDB database region - Set
ASTRA_DB_KEYSPACE
to your AstraDB keyspace - Set
ASTRA_DB_APPLICATION_TOKEN
to your AstraDB application token - Remove
JSON_API_URL
,JSON_API_AUTH_URL
,JSON_API_AUTH_USERNAME
,JSON_API_AUTH_PASSWORD
.
- Copy the
.env.example
file to.env
and fill in the values for the environment variables. - Set
IS_ASTRA
tofalse
- Set
JSON_API_URL
tohttp://127.0.0.1:8181/v1/ecommerce_test
- Set
JSON_API_AUTH_URL
tohttp://127.0.0.1:8081/v1/auth
- Set
JSON_API_AUTH_USERNAME
tocassandra
- Set
JSON_API_AUTH_PASSWORD
tocassandra
- Remove
ASTRA_DB_ID
,ASTRA_DB_REGION
,ASTRA_DB_KEYSPACE
,ASTRA_DB_APPLICATION_TOKEN
- Run
npm install
- Run
npm run seed
- Run
npm run build
to compile the frontend - (Optional) set
STRIPE_SECRET_KEY
to a test Stripe API key in your.env
file. This will allow you to enable Stripe checkout. - Run
npm start
Runnpm run test:smoke
to run a smoke test againsthttp://127.0.0.1:8888
that creates a cart using Axios. - Visit
http://127.0.0.1:8888/
to see the UI
Then run npm test
.
$ npm test
> test
> mocha ./test/*.test.js
Using test
Add to Cart
✔ Should create a cart and add a product to the cart
✔ Should find the cart and add to the cart
✔ Should find the cart and increase the quantity of the item(s) in the cart
Checkout
✔ Should do a successful checkout run
Get the cart given an id
✔ Should create a cart and then find the cart.
Products
✔ Should get all products.
Remove From Cart
✔ Should create a cart and then it should remove the entire item from it.
✔ Should create a cart and then it should reduce the quantity of an item from it.
8 passing (112ms)