# Elide Global

> Build metadata, Elide.serve, and the exported fetch handler.

`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()`:

```js
const server = Elide.serve({
  port: 3000,
  hostname: "127.0.0.1",
  fetch(request) {
    return new Response("hello");
  },
});
```

- `elide run` does not exit until `close()` is called.
- It serves HTTP/1.1, and HTTP/2 over TLS.
- Request and response bodies stream; return a `Response` backed by a `ReadableStream` to stream output.
- `request.signal` aborts when the client disconnects.
- Responses are sent as returned and never recompressed; set `Content-Encoding` and `Vary: Accept-Encoding` yourself.

## Exported fetch handler

An entry ES module can default-export an object with a `fetch(request)` method instead:

```js
export default {
  hostname: "127.0.0.1",
  port: 3000,
  fetch(request) {
    return new Response(new URL(request.url).pathname);
  },
};
```

- `elide run`, `elide serve`, and `elide dev` start it after the module, including top-level `await`, finishes.
- Imported modules never start a server.
- `fetch` is called with the exported object as `this` and returns a `Response` or a Promise of one.
- `run` binds the exported `hostname` and `port`, default `127.0.0.1:8080`; `--host` and `--port` override them in
  `serve` and `dev`.
