Skip to main content

Overview

Server functions let you run backend logic inside your Canvas app. Write TypeScript or JavaScript handlers that execute server-side with access to environment variables, a built-in KV store, and fetch — without managing infrastructure.

How it works

  1. Include server function source files in your deploy’s source_files map
  2. Files under api/ become HTTP endpoints at /functions/
  3. Canvas transpiles TypeScript → JavaScript via esbuild and executes your handler in a sandboxed async context

Writing a server function

Export a default function that receives a context object and returns a response:

Context object

Your handler receives a ctx object with:

Return value

Return an object with:

Key-value store

Every app has a built-in Redis-backed KV store, accessible in server functions via ctx.kv:

Calling the Mixpeek API

Use fetch to call the Mixpeek API through the Canvas proxy — credentials are injected automatically:

Deploying with source files

Include your server functions in the source_files field when deploying:

Runtime logging

console.log, console.warn, console.error, and console.info calls in server functions are captured and sent to the runtime logs system. View them in Studio or query via API.

Limitations

  • Execution timeout: 30 seconds per request
  • Request body size: 1 MB max
  • No filesystem access: Server functions run in a sandboxed context
  • No npm imports: Only fetch and the ctx APIs are available in the execution context
  • TypeScript only: .ts and .js files are supported (transpiled via esbuild)