An API to get the schedule of KRL commuter line in Jakarta and Yogyakarta using Hono and Bun, deployed to Cloudflare Workers. This API is primarily used on the web app (source code).
This API uses a daily cron job (at 00:00) to fetch the schedule of KRL commuter line in Jakarta and Yogyakarta from the official website of PT. KAI. The data is then processed and stored in a PostgreSQL database and cached in a Redis (for every once read request). All endpoints can be found in the docs.
git clone https://github.com/comuline/api.git
bun install
.dev.example.vars to .dev.varscp .dev.example.vars .dev.vars
Generate UPSTASH_REDIS_REST_TOKEN using openssl rand -hex 32 and copy it to your .dev.vars file
Run database locally
docker-compose up -d
bun run migrate:apply
# Please do this in order
# 1. Sync station data and wait until it's done
bun run sync:station
# 2. Sync schedule data
bun run sync:schedule
Rename the wrand.example.toml to wrangler.toml and fill the necessary information
Create a new PostgreSQL database in Neon and copy the connection string value as DATABASE_URL in your .production.vars file
Run the database migration
bun run migrate:apply
# Please do this in order
# 1. Sync station data and wait until it's done
bun run sync:station
# 2. Sync schedule data
bun run sync:schedule
COMULINE_ENV to your .production.vars fileCOMULINE_ENV=production
Create a new Redis database in Upstash and copy the value of UPSTASH_REDIS_REST_TOKEN and UPSTASH_REDIS_REST_URL to your .production.vars file
Save your .production.vars file to your environment variables in your Cloudflare Workers using wrangler
bunx wrangler secret put --env production $(cat .production.vars)
bun run deploy
TBD