[]previous and next page

bindServerFn

Gives a server function the id and url the build assigned to it.

Gives a server function the id and url the build assigned to it. The build's server transform wraps every serverFn(...) in this call; you do not call it yourself. It makes the server-side function carry the same id and url as the browser stub (serverFnStub), so a page rendered on the server can write <form action={fn.url}> for a function with form: true.

Import#

ts
import { bindServerFn } from "@shadow-js/dusk/server";

Signature#

ts
function bindServerFn<F extends ServerFnDefinition>(fn: F, id: string, base: string): F

Parameters#

Name Description
fn A function made by serverFn.
id Its stable id (letters, digits, - and _, at most 128 characters).
base Mount base of the app, "" or "/app" (no trailing slash).

Returns#

fn itself.

Throws#

  • TypeError when fn is not a serverFn() result or id is not URL-safe.
  • DuskError SERVER_FN_ALREADY_BOUND when fn already has an id.

Examples#

ts
const send = bindServerFn(serverFn({ form: true }, handler), "q3Zr0b1g2yTt0m5Qk9w3xA", "");
send.url; // "/_dusk/fn/q3Zr0b1g2yTt0m5Qk9w3xA"