Brew Lambda

Brew Lambda: server code of your page

Your code runs on BrewPage when visitors save, comment or press your button. They never see it. Free with a profile.

  1. 1A visitor saves or taps a button

  2. 2Your code runs on BrewPage

  3. 3You get a notice, the visitor an answer

What it does

Adds an action: booking

Ana books Monday 10:00; no one else can, and you get a notice.

See the code →

Checks a save: a form

After 20 December it answers “Sign-up closed”; emails are stored in lower case.

See the code →

Reacts: comment moderation

Spam is removed; each new thread gets a thank-you.

See the code →

What you need

For developers

One file, lambda.js, beside the page or site: plain JavaScript and five bp modules.

Local start

In a folder with index.html, lambda.js and state.json

npx brewpage-data@0.2.1 dev
# page:   http://localhost:8787/  (save here)
# viewer: http://localhost:8787/_bp/dev/  (entries, notices, runs, logs)

Four shapes

  1. A visitor savesbeforeWriterefuse or fixStoredonEntryruns after
  2. A visitor commentsPostedonCommentreply or remove
  3. bp.lambda("book")from your pageendpoints.bookup to 2 sAnswer to the page
ExportReturns
beforeWrite(event, bp)Nothing to accept, {refuse: "text"} or {value}
onEntry(event, bp)Nothing; the visitor never waits
onComment(event, bp)Nothing
endpointsJSON answer to bp.lambda("book", body); up to 2 actions

lambda.js · booking with a notice

const SLOTS = ["mon-10", "mon-11", "tue-10"];
export const endpoints = {
  async book(req, bp) {
    const { slot, name } = req.body || {};
    if (!SLOTS.includes(slot) || !name) return { ok: false, error: "Pick a slot and enter your name." };
    const taken = await bp.data.create("slots", slot, { taken: true });
    if (!taken) return { ok: false, error: "Sorry, this slot was just taken." };
    await bp.data.add("bookings", { slot, name, visitor: req.visitor.id });
    await bp.notify.owner({ title: "New booking", text: `${name}, ${slot}` });
    return { ok: true };
  }
};

On the page

const r = await bp.lambda("book", { slot, name }); if (!r.ok) showError(r.error);

What code can use

ModuleWhat it does
bp.dataThe page's lists; create takes a key once
bp.commentsList, reply, remove
bp.notifyowner() sends you a notice
bp.siteList site files; write .json, .txt, .csv
bp.accountYour other pages, once allowed

Plain JavaScript:fetchURLcryptoconsoleDateJSONIntl.DateTimeFormatIntl.NumberFormat

fetch reaches public https:// only. No timers, eval, import or WebSocket; most such errors name an alternative.

Logs and counters

console.log goes to the run's log; the manage panel, API and MCP show the switch, counters and last runs.

From a script

curl https://brewpage.app/api/<ns>/<id>/lambda -H "X-Owner-Token: <profile token>"

Limits per run

Before a save 300 msYour action 2 sAfter a save 10 sMemory 16 MBfetch after a save 5, in an action 3Code 32 KBEvent 64 KBAction in 16 KB / out 64 KB

All limits: Help → Limits.

Test and publish

createDev() runs the same engine and limits in tests:

test.mjs

import { createDev } from "brewpage-data/dev";
const dev = await createDev({ dir: "." });
const r = await dev.call("book", { slot: "mon-10", name: "Ada" });
assert.deepEqual(r, { ok: true });
assert.deepEqual(dev.notices(), [{ title: "New booking", text: "Ada, mon-10" }]);
await dev.close();

Publish the folder

BREWPAGE_OWNER_TOKEN=<profile token> npx brewpage-data@0.2.1 publish

Agents: the publish tool's lambda field. API: "lambda": "<lambda.js>" beside content and state (API → Brew Lambda). Live page, read-only: npx brewpage-data@0.2.1 dev --live <link>.

More examples

Sign-up closes on a date, email tidied

export function beforeWrite(event) {
  if (event.collection !== "signups") return;
  if (Date.now() > Date.parse("2026-12-20T18:00:00Z")) return { refuse: "Sign-up closed on 20 December." };
  const email = String(event.value.email || "").trim().toLowerCase();
  if (!email.includes("@")) return { refuse: "Please enter a valid email." };
  return { value: { ...event.value, email } };
}

Call an API after a save

export async function onEntry(event, bp) {
  if (event.collection !== "orders") return;
  const res = await fetch("https://api.example.com/rates?base=EUR");
  if (!res.ok) { console.warn("rates unavailable", res.status); return; }
  const data = await res.json();
  await bp.data.set("rates", "eur", { usd: data.rates.USD, at: new Date().toISOString() });
}

Comment moderation

export async function onComment(event, bp) {
  if (/casino|giveaway|free money/i.test(event.comment.text)) {
    await bp.comments.remove(event.comment.id);
    return;
  }
  if (!event.comment.parentId) await bp.comments.reply(event.comment.id, "Thanks for your comment!");
}

For AI assistants

Paste it into your assistant and add your task.

Prompt: build it locally, then publish

Add Brew Lambda server code to my BrewPage page. Read https://brewpage.app/llms-lambda.txt first.
Make a folder with index.html, lambda.js and state.json, and test it with npx brewpage-data@0.2.1 dev before publishing.
Publish with my profile token: npx brewpage-data@0.2.1 publish, or the BrewPage publish tool with the lambda field.
Give me the page link and the private manageUrl.
What the code should do:

FAQ

Can visitors see my code?

No. It runs only on BrewPage's servers; no page, preview or link shows it.

What if my code fails?

The save still goes through; the error shows in your runs. Only beforeWrite can stop a save, with your text or a generic message.

Does it work on my own domain?

Yes, on a connected custom domain too.