This e-commerce applications uses the following services - Yugabyte Cloud, Hasura Cloud, and Vercel. The project has one external service dependency for payment handling, which we've chosen to implement with Stripe. User authentication and authorization, cart management, order management and product information management is stored in Yugabyte Cloud and architected through Hasura Cloud GraphQL Engine. Minio is currently not supported for this deployment option.
Service | Functionality |
---|---|
Yugabyte Cloud | PIM, Cart Management, User Management, User Authentication, Order Management |
Hasura Cloud | Business Logic Routing, Unified API, Access Control Management |
Vercel for NextJS | Serverless business logic handlers, web application framework |
Stripe | Payment handling |
Follow the steps below to run the apllication in the cloud using Hasura Cloud, Yugabyte Cloud and Vercel.
-
Deploy and interconnect your Hasura Cloud and Yugabyte Cloud instances.
-
Navigate to the
hasura
directory:cd hasura
-
Create the
config.yaml
file from the template for cloud deployments:cp cloud.config.yaml config.yaml
-
Open the
config.yaml
file and initialize two parameters:endpoint
- use the value of theGraphQL API
property of your Hasura Cloud project (without/v1/graphql
in the end).handler_webhook_base_url
- same as above.admin_secret
- use the value of theAdmin Secret
property.
-
Create the
metadata/databases/databases.yaml
file from the template for cloud deployments:cp metadata/databases/cloud.databases.yaml metadata/databases/databases.yaml
-
Open the
metadata/databases/databases.yaml
file and update one parameter:database_url
- use the value of theConnection String
property. Put in quotes in the config file.
-
Apply metadata and load sample data:
hasura metadata apply hasura migrate apply hasura metadata reload hasura seeds apply
Follow these steps to deploy the app to Vercel and connect it to the Hasura Cloud service and your Stripe account (if you need checkout to work).
-
Log in to your Vercel account.
-
Create a new Vercel project by importing the project's Git repository
-
Configure the project:
- Framework Preset - select
Next.js
- Root Directory - set to
www
- Environment Variables:
NEXT_PUBLIC_HASURA_URL_SERVERSIDE
- the value of theGraphQL API
property of your Hasura Cloud project (without/v1/graphql
in the end).NEXT_PUBLIC_HASURA_URL_CLIENTSIDE
- same as above.HASURA_ADMIN_SECRET
- theAdmin Secret
property from your Hasura Cloud project.NEXT_PUBLIC_HASURA_CLOUD_ADMIN_SECRET
- same as above.HASURA_JWT_SECRET_TYPE
- set toHS256
.HASURA_JWT_SECRET_KEY
- set tothis-is-a-generic-HS256-secret-key-and-you-should-really-change-it
(or your custom key if you changed the default value).
- Framework Preset - select
-
Deploy the Project.
-
Open the app, once the project is deployed!
Your Hasura Cloud instance needs to know the address of the Vercel application to call several API endpoints. The APIs are implmented under the www\pages\api
directory.
-
Open Hasura Cloud project's settings.
-
Add a new environment variable
NEXTJS_SERVER_URL
that refers to the address of your Vercel application instance (for instance,https://hasura-ecommerce.vercel.app
) -
Wait while Hasura updates the metadata. You should NOT have any metadata conflicts after this step is over.
The application can use Stripe for the checkout feature. Follow these steps to connect Stripe to your app running in Vercel:
-
Create a Stripe account.
-
Navigate to the Developers dashboard.
-
Configure a new Webhook asking Stripe to update the Vercel application on the payment status changes:
- Endpoint URL - the format is
{your_vercel_app_URL}/api/webhooks/stripe
(for instance,https://hasura-ecommerce.vercel.app/api/webhooks/stripe
) - Events to Listen - select to listen to all the events under the
payment_intent.*
category.
- Endpoint URL - the format is
-
Go to the Developers->API keys screen and find the
Publishable key
andSecret key
parameters. -
Open the Settings->Environment Variable dashboard of your Vercel application and add these parameters there:
STRIPE_SECRET_KEY
- your Stripe secret key.STRIPE_PUBLISHABLE_KEY
- your Stripe publishable key.
-
Redeploy the Vercel app to apply the changes.
Note, you don't need to follow the steps below if you deployed the app to Vercel. These instructions are for running the app locally.
-
Go to the root directory of the project.
-
Create the
.env
file:cp .env.cloud.example .env
-
Open the
.env
file and initialize parameters:HASURA_CLOUD_URL
- your Hasura Cloud GraphQL API URL (without/v1/graphql
in the end)HASURA_CLOUD_ADMIN_SECRET
- your Hasura Cloud admin secret.STRIPE_*
- stripe related parameters if you want checkout to work.
-
Start the application locally with Docker:
docker-compose -f docker-compose-cloud.yaml up
-
Visit the following endpoints:
Visit http://localhost:3000 for Next.js frontend Login at /account/login has default credentials "[email protected]:password" Login at /admin/account/login has default credentials "[email protected]:password" Visit http://localhost:8060 for Hasura console (admin secret = "my-secret") Visit http://localhost:9000 for Minio dashboard (login = "minio:minio123") Visit http://localhost:7001 for Yugabyte Master UI Visit http://localhost:9001 for Yugabyte TServer UI