Back end
Back end
Accent
Scheme
Backdrop motion
Back end

Back end

A server fn runs on a server (Bun) and the page calls it by name: no routes, no fetch, no JSON by hand. This page's back end is the same file as the page: a guest book in SQLite, accounts, values kept live, events and notifications.
The back end is hereThe page asks once, with a cheap server fn and an else. Nothing on this page opens a socket or calls the back end until the page is visited, and nothing else in the playground needs one.
ping() answered "pong"
Everything below is live. Open this page in a second window to see it stay current.

Calls

A server fn is called like any fn that can fail: with ?, with else, from a resource.
server fnIts parameters need types, and what arrives is checked against them before it runs. fail(…)? ends it with words the page's else gets. The price list is a fn only the back end uses, so it never reaches the page; env("KEY") reads the server's surroundings.
itemone of them is not sold
qty2
Ask for a quote. Try the unicorn, a qty of 0, and the wrong type.
The back end's own filesfs in a server fn is the server's folder (MOTE_DATA, .data beside the entry under mote dev), not the browser's. One file holds a number.
1visits to this page, by anyone, ever
It counted you when the page opened. Restart the back end: the number is still there.
bytes across a callA server fn takes and gives bytes as they are: no base64 by hand. Here the page sends the words as bytes, the back end packs them with zip.gzip and sends the packed bytes back; the page unpacks them to check. A call is 16 MB at most (MOTE_MAX_BODY).

Kept current

A guest bookThe back end's own SQLite. The list is a live value over a server live fn: sent once, and again to every open page whenever a server fn says changed("guests"). Sign it here and watch another window.
Nobody has signed yet. Be the first.
live entries: 0 rows, newest first

People

The back end keeps the accounts (passwords hashed) and a session cookie scripts cannot read.
authauth.signUp, auth.signIn, auth.signOut and auth.me: from the page each is a call to the back end. Make any account you like; it lives in this back end's data folder.
auth.me() is none: nobody is signed in.
requires signedInA server fn marked so is refused ("sign in first") for anyone else, before it runs. Inside it, auth.me() is who made this call.
signed out
Press it signed out, then sign in beside it and press again.

Said by the back end

The same WebSocket carries events to pages that are open, and Web Push reaches devices that are not.
emit, emitTo, onemit(name, value) tells every open page; emitTo(userId, …) only that person's. A page hears one with on name(e: …). Wave, and every window on this page counts it.
0 waves heard by this page
Nothing heard yet.
emitTo needs someone to send to: sign in to try Poke.
A call between windowsrtc.join(room, {…}) connects this window to every other in the room, browser to browser; the back end only says who may be in it (server call) and passes the notes they need to find each other. call.peers is who is there; video of=p is their picture; their sound plays by itself.
Open this page in a second window, type the same word there, and join in both: the two hear each other. (Wear headphones, or it howls.)
notify through the back endnotify.send(userId, {title, body, url}) in a server fn puts it in that person's inbox, tells their open pages (on notified) and pushes it to devices that said notify.enable(). The page reads notify.inbox() and marks with notify.read(id).
Notifications are for whoever is signed in: sign in above, and an inbox appears here.

Shipping it

mote buildFor a program with server fns, mote build writes server/main.js beside index.html and says what stayed out of the page. Bun serves the page and answers its calls; mote dev runs both. This is what it prints for the whole playground, cut short where it lists every call, every model and each extension's parts (the first two lines are the page itself, with their sizes left out).
dist/index.html … bytes (… of JavaScript) dist … bytes in all, with icon-192.png, icon-512.png, manifest.webmanifest, …, sw.js dist/server/main.js 267934 bytes: the back end, answering backendPing, backendQuote, backendPack, backendVisit, …, pgDataSlow, pgDataHit, …, usagePeople, …, adminLogs described in: api.json (beside it, and never served) only on the back end, not in the page: adminAll, …, backendPrice, pgDataWait, usageBounds, … run it with: bun dist/server/main.js --port 4870 for whoever runs it: dist/Dockerfile and dist/.env.example (9 setting(s) of the program's own); 4 file(s) also as .gz models (schema 4), and what the page may do: PgNote read, add, change, remove anyone PgOrder read, add anyone · change, remove closed PgMember closed to the page: only the back end's own code reaches it …
esc
Pages
StartStart
Buttons & badgesComponents
Cards & disclosureComponents
Dialogs & drawersComponents
Menus & commandsComponents
Dates & tablesComponents
ChartsComponents
Chart galleryComponents
FieldsComponents
ChoicesComponents
DisplayComponents
NavigationComponents
Popovers & sheetsComponents
MessagesChat & AI
Prompt inputChat & AI
Reasoning & toolsChat & AI
Developer partsChat & AI
ConversationChat & AI
Code artifactsChat & AI
VoiceChat & AI
Code blocksChat & AI
MarkdownChat & AI
EditorElements
TerminalElements
FlowElements
3D boxesElements
PaintElements
SurfaceElements
MediaElements
IconsElements
PrimitivesElements
SQLBatteries
StorageBatteries
Net & resourcesBatteries
Crypto & bytesBatteries
ZipBatteries
TablesBatteries
PDFBatteries
TimeBatteries
ImagesBatteries
ScanBatteries
Video & audioBatteries
SearchBatteries
SyntaxBatteries
PatternsBatteries
NotifyBatteries
ShareBatteries
State & logicLanguage
WorkersLanguage
Events & elementsLanguage
StylingLanguage
RoutesLanguage
ShortcutsLanguage
Long listsLanguage
Failures & tryLanguage
Back endBack end
Models & writesBack end
Rules & failuresBack end
Jobs & schedulesBack end
Running itBack end
ExtensionsBack end
AIBack end
AnalyticsBack end
AboutAbout
↑↓move
↵open
676 places · ranked by BM25