Elide is a global with build metadata and the serve() HTTP entry point.
| Property | Type |
|---|---|
version | string |
debug | boolean |
release | boolean |
buildMode | string |
targetArchitecture | string |
Elide.serve(options)
Elide.serve takes a Fetch-style handler and returns an object with port, hostname, and close():
const server = Elide.serve({
port: 3000,
hostname: "127.0.0.1",
fetch(request) {
return new Response("hello");
},
});elide rundoes not exit untilclose()is called.- It serves HTTP/1.1, and HTTP/2 over TLS.
- Request and response bodies stream; return a
Responsebacked by aReadableStreamto stream output. request.signalaborts when the client disconnects.- Responses are sent as returned and never recompressed; set
Content-EncodingandVary: Accept-Encodingyourself.
Exported fetch handler
An entry ES module can default-export an object with a fetch(request) method instead:
export default {
hostname: "127.0.0.1",
port: 3000,
fetch(request) {
return new Response(new URL(request.url).pathname);
},
};elide run,elide serve, andelide devstart it after the module, including top-levelawait, finishes.- Imported modules never start a server.
fetchis called with the exported object asthisand returns aResponseor a Promise of one.runbinds the exportedhostnameandport, default127.0.0.1:8080;--hostand--portoverride them inserveanddev.