Skip to main content
Complete reference for building and deploying applications on Hiveku’s serverless infrastructure.
Platform: AWS Lambda + CloudFront + S3 | Runtime: Node.js 20.x on ARM64 | Not supported: PHP, WebSockets, native modules without layers, persistent processes

Architecture

  • Static assets are built and uploaded to S3, served via CloudFront CDN (global edge locations)
  • Automatic HTTPS with wildcard certificate
  • URL rewriting for clean routes (/about/about/index.html)
  • Cache: HTML 1 min, CSS/JS 5 min
  • Each API route becomes a Lambda function with its own URL
  • SSR pages are bundled with the server runtime

Resource Limits

Do’s and Don’ts

  • Use pure JavaScript packagesbcryptjs, pg (pure mode), jose for JWT
  • Keep functions small — split large APIs into separate files for faster cold starts
  • Use environment variables — store secrets in Hiveku’s env vars, not in code
  • Optimize bundle size — use dynamic imports, tree-shaking, avoid bundling dev deps
  • Use S3 for large files — generate presigned URLs for uploads over 6MB
  • Return proper status codes — use 200, 201, 400, 401, 404, 500 appropriately
  • Set cache headers — use Cache-Control for static responses
  • Handle cold starts — initialize DB connections outside the handler

API Routes

Where to Place API Files

Hiveku auto-detects API routes from these directories:

File to URL Mapping

API Handler Formats

Hiveku supports two function formats — use whichever you prefer:

hiveku.json Configuration

Create a hiveku.json in your project root to customize deployment:

Advanced Features

Lambda Layers

Auto-provisioned layers for native dependencies. These packages just work when you add the layer: sharp bcrypt argon2 canvas prisma ffmpeg puppeteer

Scheduled Functions (Cron)

Add a @schedule comment or put files in a cron/ directory:
Cron format: cron(min hour day-of-month month day-of-week year) Rate format: rate(5 minutes), rate(1 hour), rate(1 day), rate(7 days)

Streaming Responses

SSE and chunked responses for AI apps. Auto-detected from text/event-stream content type:

Package Compatibility

Code Patterns

Database Connection (Prisma)

Initialize the Prisma client outside the handler so connections are reused across Lambda invocations. Use connection pooling and keep-alive pings to avoid cold reconnect latency.
Set connection_limit and pool_timeout in your DATABASE_URL query string. A limit of 10-15 connections with a 30s timeout works well for serverless.

JWT Authentication

Use the jose library for JWT — it’s pure JavaScript and works on Lambda. Avoid jsonwebtoken as it has native dependencies.

Large File Upload (S3 Presigned URL)

Custom CORS Headers

Reusable Auth Middleware

Environment Variables

Auto-Injected Variables

These are available in every Lambda function automatically:

Build-Time vs Runtime

  • NEXT_PUBLIC_* variables are bundled at build time and exposed to the browser
  • All other variables are available only at runtime, server-side only
NEXT_PUBLIC_* variables require a redeploy to take effect after changes.

Troubleshooting

Check if you’re hitting the 30s default timeout. Increase in hiveku.json, or optimize your code. Database queries without connection pooling are a common cause.
Use dynamic imports, check for accidentally bundled devDependencies, exclude large assets. Consider splitting into multiple functions.
You’re using a package with native bindings (bcrypt, sharp, etc.). Switch to a pure JS alternative or request a Lambda Layer.
Hiveku adds CORS headers automatically. If you still see errors, check your frontend is calling the correct URL and your API returns proper response format.
Make sure the variable is set in Hiveku dashboard. NEXT_PUBLIC_* vars need a redeploy to take effect. Server-side vars are only available in Lambda, not the browser.
Reduce bundle size, increase memory (more memory = faster CPU), minimize top-level imports. Consider keeping functions warm with scheduled pings.
Lambda can scale to many instances. Use a connection pooler (Supabase, PlanetScale) or set your pool size to 1-2 connections per function.
Lambda /tmp is ephemeral. Files may persist between invocations on the same instance but will be cleared. Use S3 for persistent storage.