Skip to content
cloudhost
Functions

Code that runs on request.

Write a fetch handler and deploy it. It runs on every request, sleeps when idle, and is billed per request and active CPU time.

Web standards, not a private API

A function is a module with a fetch handler, the standard WinterTC shape. Request, Response, fetch, crypto and streams are the ones you know from the browser, and Node built-ins are available too.

export default {
  async fetch(request: Request, env: Env) {
    const url = new URL(request.url)
    return Response.json({ hello: url.searchParams.get("name") ?? "salam" })
  },
}

What you get

  • Runs on request

    No server to keep on, no capacity to set. It runs when a request comes in and sleeps when idle.

  • Cron schedules

    Up to 5 cron expressions per function, in any time zone; Tehran by default. Each tick runs at most once.

  • Secrets

    Secrets are stored encrypted and never shown again. They are opened only in the function's memory.

  • Live logs

    console.log, requests and cron runs, live in the terminal or the dashboard.

  • Observability and alerts

    Requests, 4xx and 5xx errors and p50/p95/p99 per route over an hour, a day or a week. Alerts by email, SMS or webhook.

  • Versions and rollback

    Every deploy is an immutable version; going back is one command.

  • Bound to your data

    env.DB for the database, env.CACHE for the cache, env.BUCKET for a bucket. No connection strings or keys in your code.

  • Outbound fetch

    A function can call any public API. Internal network addresses are blocked.

  • A preview per branch

    Pushing a branch gives it a test address of its own.

A nightly job, no server

Every day at 3 a.m. Tehran time, old carts are cleared. The database is awake for those few seconds only.

name = "reports"
type = "function"
main = "index.ts"

[[db]]
binding = "DB"
database = "shop"

[triggers]
crons = ["0 3 * * *"]

Per request and active CPU

Each run counts as one request, plus the time your code actually spent on the CPU. Waiting for a database or an outside API does not count. Hobby includes a free amount each month.

Questions

Deploy your first function

One file, one command, one address.

Sign-up is by invite for now. If you have a code, create your account.

Sign up withEmail codeSMS code