Skip to content

ably-labs/live-comments

Repository files navigation

LiveComments Example app

An example application with posts and comments that uses the Models SDK and Ably Database Connector.

The app uses Next.js, and Prisma.

Getting started

First, set up environment variables by copying them from the template:

cp env.example env.local

Update your env.local file with the following:

POSTGRES_URL="postgres://postgres:postgres@localhost:5432/postgres"
POSTGRES_URL_NON_POOLING="postgres://postgres:postgres@localhost:5432/postgres"
POSTGRES_USER=postgres
POSTGRES_HOST=localhost
POSTGRES_PASSWORD=postgres
POSTGRES_DATABASE=postgres
SESSION_SECRET=somesecret
NEXT_PUBLIC_ABLY_API_KEY=<YOUR_ABLY_API_KEY>
  • Replace <YOUR_ABLY_API_KEY> with your Ably API Key

Note You can get a free Ably API Key at https://ably.com

Export the environment variables in your shell session:

export $(grep -s -v "^#" env.local | xargs) # export environment variables

Now spin up a PostgreSQL database and an instance of adbc which publishes change events written to the outbox table over Ably channels.

docker compose up --build -d

Now we can create the necessary tables in the database and create some seed data:

pnpm install # first install dependencies
pnpm run db 

You can now start the example app:

pnpm run dev

Open the app on localhost:3000.

Navigate to a post and try adding, editing and removing comments from multiple tabs and see the changes reflected to all users in realtime!