A SvelteKit + Cloudflare Pages app to collect daily Ramadhan activity sheets.
- Student identity lookup by NIS (proxied through server-side API route)
- Auto-filled, disabled identity fields (
nama lengkap,rombel) after NIS is found - Daily input fields for:
- tanggal
- sholat fardhu (multiple)
- status puasa (with required reason if not full)
- ibadah sunnah (multiple)
- tadarus al-qur'an
- 7 kebiasaan anak indonesia hebat (multiple)
- Data stored in Cloudflare D1
- SvelteKit 2 + Svelte 5
- Bun runtime / package manager
- Cloudflare Pages adapter
- Cloudflare D1
- Cloudflare account
- Bun installed
- Wrangler CLI available (
bunx wrangler --version)
-
Copy
wrangler.example.tomltowrangler.toml:cp wrangler.example.toml wrangler.toml
-
Update
wrangler.toml:name[[d1_databases]].database_name[[d1_databases]].database_id
-
Add the external identity API URL in
wrangler.tomlas an env var:[vars] IDENTITY_API_URL = "https://your-identity-service.example/api/identity/student" # Optional override. If omitted, app derives <origin>/sanctum/csrf-cookie from IDENTITY_API_URL IDENTITY_CSRF_URL = "https://your-identity-service.example/sanctum/csrf-cookie" # Optional override. If omitted, app derives <origin>/assembly-login from IDENTITY_API_URL IDENTITY_LOGIN_URL = "https://your-identity-service.example/assembly-login"
-
Authenticate Wrangler:
bunx wrangler login
For Drizzle Kit commands (migrations, introspect), set:
export CLOUDFLARE_ACCOUNT_ID="<your-account-id>"
export CLOUDFLARE_D1_DATABASE_ID="<your-database-id>"
export CLOUDFLARE_API_TOKEN="<your-api-token>"bun install
bun run db:apply:local
bun run devCloudflare Pages runtime parity (uses Wrangler locally after build):
bun run dev:wranglerCloudflare Pages with live reload (rebuilds on file changes):
bun run dev:wrangler:watchThis runs both vite build --watch and wrangler pages dev --live-reload in parallel, so your changes trigger automatic rebuilds and the browser refreshes automatically.
bun run check
bun run buildApply schema to remote D1:
bun run db:apply:remoteSchema file: schema.sql
Create a Pages project named ramadhan-sheet from Cloudflare Dashboard or with Wrangler.
If you use Git integration in Dashboard:
- Framework preset:
SvelteKit - Build command:
bun run build - Build output directory:
.svelte-kit/cloudflare
In Cloudflare Dashboard -> Workers & Pages -> ramadhan-sheet -> Settings:
- Bind your D1 database with binding name:
DB - Add env var:
IDENTITY_API_URL - (Optional but recommended for Laravel Sanctum) Add env var:
IDENTITY_CSRF_URL - (Optional) Add env var:
IDENTITY_LOGIN_URL
These names must match server code usage (platform.env.DB, platform.env.IDENTITY_API_URL, platform.env.IDENTITY_CSRF_URL, platform.env.IDENTITY_LOGIN_URL).
bun run build
bun run deploy:wranglerOr deploy via Wrangler directly:
wrangler pages deploy .svelte-kit/cloudflare-
Database tidak tersediafrom API:- Ensure D1 binding name is exactly
DBin Pages settings. - Ensure
[[d1_databases]].binding = "DB"exists inwrangler.toml.
- Ensure D1 binding name is exactly
-
IDENTITY_API_URL belum dikonfigurasi:- Add
IDENTITY_API_URLin Pages project environment variables. - If testing locally, add
[vars]withIDENTITY_API_URLinwrangler.toml.
- Add
-
Browser CORS error about
loopbackaddress space:- Ensure frontend uses the internal endpoint (
/api/identity/student) instead of calling the identity service directly from browser. - For Laravel Sanctum-protected identity API, set
IDENTITY_CSRF_URL(or keep default derived/sanctum/csrf-cookie) and keep both domains HTTPS.
- Ensure frontend uses the internal endpoint (
-
Build succeeds but API fails after deploy:
- Confirm you deployed the latest build (
bun run buildthenbun run deploy). - Re-check Pages production bindings (
DB,IDENTITY_API_URL) after creating new environments.
- Confirm you deployed the latest build (
-
wrangler pages deploypermission/auth error:- Run
bunx wrangler loginagain. - Verify you are using the correct Cloudflare account.
- Run
-
D1 schema/table errors at runtime:
- Apply schema to remote DB:
bun run db:apply:remote. - Verify tables exist in the same D1 database ID configured in
wrangler.toml.
- Apply schema to remote DB: