serve() options
How the port is chosen, hostname, the body size limit and the startup banner
import { } from "@senrijs/senri/serve";
const = await (, {
: 8080,
: "127.0.0.1",
: 1024 * 1024 * 1024, // 1 GiB
});
.; // "http://127.0.0.1:8080"
await .(); // stops after waiting for in-flight requestsserve() from @senrijs/senri/serve detects the runtime (Bun, Deno or Node.js) and starts the app. On start, it prints the URL and the registered routes (banner: false turns this off).
How the port is chosen
The first one found is used:
- The
portoption (0picks a free port) - The
PORTenvironment variable 3927
- If
PORTis not a number or out of range, it throws instead of silently listening on another port - On Deno,
PORTis read only with permission to read it (--allow-env=PORT). Without it,3927is used without a prompt - Read the chosen port from
server.port
Body size limit (maxRequestBodySize)
The limit (in bytes) of bodies the whole server takes. Over it, the response is 413.
- Without it, there is no limit on any runtime (it does not use the 128 MiB default of
Bun.serveeither) - With Content-Length, the request is refused before reading. Without it (chunked transfer), the body is counted as it is read
- The limit for reading bodies is set by the app's
createApp({ maxBodySize })(1 MiB by default) and a route'sbodyLimit()(Request bodies and limits)
Options
Prop
Type
Return value
Prop
Type