---
title: "fetchServer"
description: "Serves `vite dev` requests through the Fetch handler an application's server module exports. Every request Vite does not answer itself goes to the current `default.fetch` of `entry`, loaded through the environment's module runner on each request, so an edit applies to the next request. Errors go to Vite's development error page."
url: "https://pitlane.tools/package/vite-plugin-fetch-server/function/fetchServer"
---

# fetchServer

```ts
import { fetchServer } from "@pitlane/vite-plugin-fetch-server";
```

```ts
function fetchServer(options): Plugin;
```

Serves `vite dev` requests through the Fetch handler an application's server module exports. Every request Vite does not answer itself goes to the current `default.fetch` of `entry`, loaded through the environment's module runner on each request, so an edit applies to the next request. Errors go to Vite's development error page.

Development only: the plugin takes no part in `vite build` or `vite preview`. It sets `appType: "custom"` unless the config sets one.

## Parameters

### options

[`FetchServerOptions`](https://pitlane.tools/package/vite-plugin-fetch-server/interface/FetchServerOptions.md)

The server module and the environment that loads it; see [FetchServerOptions](https://pitlane.tools/package/vite-plugin-fetch-server/interface/FetchServerOptions.md)

## Returns

`Plugin`

The plugin, passed to Vite as one entry of `plugins`

## Throws

Error when `entry` is missing or empty

## Throws

Error at dev server startup when `environment` does not exist or is not runnable

## See

[Fetch server guide](https://pitlane.tools/guides/fetch-server.md)

## Example

```ts title="vite.config.ts"
import { fetchServer } from "@pitlane/vite-plugin-fetch-server";
import { defineConfig } from "vite";

export default defineConfig({
    plugins: [fetchServer({ entry: "src/http.ts" })],
});
```
