Backend for the Emote Widget
- Create an Heroku application:
heroku create <app-name>
- Add Heroku Key-Value Support:
heroku addons:create heroku-redis:mini
- Add Apache Kafka on Heroku Support:
heroku addons:create heroku-kafka:basic-0
- Create an Apache Kafka Topic
heroku kafka:topics:create emotes
- Deploy to Heroku
git push heroku main
Enable pnpm
with corepack
:
corepack use pnpm
Install dependencies:
pnpm install
Run Server in development mode:
pnpm run start:dev
REDIS_URL
- A Redis connection stringKAFKA_CLIENT_CERT
- Kafka client certificateKAFKA_CLIENT_CERT_KEY
- Kafka client private keyKAFKA_PREFIX
- Kafka prefix (For multitenant plans on Heroku)KAFKA_TRUSTED_CERT
- Kafka trusted certificateKAFKA_URL
- Kafka brokers urlsRATE_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)
Returns the votes by Event
id
- Represents an Event by ID
{
"smile": 100,
"love": 103,
"plus_one": 5,
"question": 1
}
Submit a vote by Event
id
- Represents an Event by ID
{
"emote": "smile"
}
Body
{
"message": "emote received"
}
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
}
Connect to an event stream by Event ID
emote
- Anemote
has been received - (data:smile
)votes
- Avotes
state object has been received (data:{"smile": 1, "question": 3}
)