Skip to content

Development server

Serve a directory with page reload using elide dev or elide serve, run a Fetch-style handler, and run a server across several Elide contexts.

On this page

elide dev and elide serve serve a directory of files or run a server script.

Terminal
bash
elide dev ./public
elide serve ./dist
CommandDefault addressReload on file change
elide dev127.0.0.1:3000HTML pages, when serving a directory
elide serve127.0.0.1:8080No

A directory starts a file server; a script runs as a program and is not reloaded.

Starting the development server and observing a changed page
 ~/demo  elide dev site --no-tui --port 43765 &
Dev server for directory: "site"
Dev server: site at http://127.0.0.1:43765
 ~/demo  curl -s http://127.0.0.1:43765 | head -2
GET / 200 (164us)
<!doctype html>
<h1>Hello, Ada!</h1>
 ~/demo  sed -i.bak 's/Ada/Grace/' site/index.html
[watch] Create /home/demo/demo/site/sedsHkWQG
 ~/demo  curl -s http://127.0.0.1:43765 | head -2
GET / 200 (112us)
<!doctype html>
<h1>Hello, Grace!</h1>
 
FlagEffect
--host HOSTBind host.
--port PORTBind port.
--no-tuiPlain log output instead of the TUI.
--no-watchdev only: no watching or reload.
--contexts=NRun N copies of the app; auto sizes from the CPU cores. Linux only.

Serve a directory

RequestResponse
/, /docs, /docs/The directory’s index.html
A directory without index.html404; there are no directory listings
/about when only about.html exists404; link to about.html
A dot file such as /.env404. /.well-known/ is served.
A symbolic link that points outside the directory, or .. in the path404
POST and other methods405 from elide serve; elide dev answers as for GET
  • Content-Type comes from the file extension: text/html; charset=utf-8, text/css, text/javascript, application/json, application/wasm, image/png and so on.
  • Files are sent whole, uncompressed, with no ETag, Last-Modified or Cache-Control; Range and conditional requests get a full 200. Put a CDN or reverse proxy in front for caching and compression.
  • elide dev adds a reload script to each HTML page and reloads it when any file in the directory changes.

Run a fetch handler

js
// entrypoint.mjs
export default {
  async fetch(request) {
    return new Response("ok");
  },
};
utf-8 · js · Lines: 6
Terminal
bash
elide serve entrypoint.mjs

elide run entrypoint.mjs also serves, on the exported hostname and port or 127.0.0.1:8080. Elide.serve({ port: 3005, fetch }) uses its own address with every command.

Serve with several contexts

Terminal
bash
elide serve --contexts=4 entrypoint.mjs
  • Each context runs the entry module once and keeps its own globals, so a request counter counts per context.
  • A connection stays on one context for its lifetime, including keep-alive requests.
  • If one context fails, the server stops.

Set engine.contexts in elide.pkl for finer control; see Engine contexts.

Samples

Was this page helpful?