Skip to content

heroku-examples/emote-server

Repository files navigation

emote-server

Backend for the Emote Widget

Installation & Deployment

Deploy

Manual Deployment

  1. Create an Heroku application:
heroku create <app-name>
  1. Add Heroku Key-Value Support:
heroku addons:create heroku-redis:mini
  1. Add Apache Kafka on Heroku Support:
heroku addons:create heroku-kafka:basic-0
  1. Create an Apache Kafka Topic
heroku kafka:topics:create emotes
  1. Deploy to Heroku
git push heroku main

Local Development

Enable pnpm with corepack:

corepack use pnpm

Install dependencies:

pnpm install

Run Server in development mode:

pnpm run start:dev

Configuration

  • REDIS_URL - A Redis connection string
  • KAFKA_CLIENT_CERT - Kafka client certificate
  • KAFKA_CLIENT_CERT_KEY - Kafka client private key
  • KAFKA_PREFIX - Kafka prefix (For multitenant plans on Heroku)
  • KAFKA_TRUSTED_CERT - Kafka trusted certificate
  • KAFKA_URL - Kafka brokers urls
  • RATE_LIMIT_ENABLE - Enable rate limitting (Default: true)
  • RATE_LIMIT_MAX - Max number of requests per time window (Default: 400)
  • RATE_LIMIT_WINDOW - Duration of the Rate Limit time window (Default: 1 minute)
  • HEARTBEAT_TIMEOUT - Duration of the Heartbeat (Default: 30 seconds)
  • EVENT_ID_LENGTH - Max length of an Event ID (Default: 32 characters)
  • EVENTS_MAX - Max number of Event Streams (Default: 32)

API

GET /api/emote/:id

Returns the votes by Event

Url Parameters

  • id - Represents an Event by ID

Output

{
  "smile": 100,
  "love": 103,
  "plus_one": 5,
  "question": 1
}

POST /api/emote/:id

Submit a vote by Event

Url Parameters

  • id - Represents an Event by ID

Body

{
  "emote": "smile"
}

Output (200 - Success)

Body

{
  "message": "emote received"
}

Output (429 - Rate Limit)

Headers

retry-after: 60000
x-ratelimit-limit: 100
x-ratelimit-remaining: 0
x-ratelimit-reset: 39

Body

{
  "error": "Too Many Requests",
  "message": "Rate limit exceeded, retry in 1 minute",
  "statusCode": 429
}

GET /api/events/:id

Connect to an event stream by Event ID

Events

  • emote - An emote has been received - (data: smile)
  • votes - A votes state object has been received (data: {"smile": 1, "question": 3})

About

Backend for the Emote Widget

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published