---
title: Invoking Entrypoints
description: Invoke JavaScript build handlers and experimental Go HTTP server entrypoints.
url: "https://nextjs.org/docs/app/api-reference/adapters/invoking-entrypoints"
docs_index: /docs/llms.txt
lastUpdated: 2026-12-01
prerequisites:
  - "API Reference: /docs/app/api-reference"
  - "Adapters: /docs/app/api-reference/adapters"
---

> For an index of all documentation, see [/docs/llms.txt](/docs/llms.txt).

Node.js and Edge entrypoints use a `handler(..., ctx)` interface, with runtime-specific request/response types. Experimental Go entrypoints are compiled HTTP servers.

## Node.js runtime (`runtime: 'nodejs'`)

Node.js entrypoints use the following interface:

```typescript
handler(
  req: IncomingMessage,
  res: ServerResponse,
  ctx: {
    waitUntil?: (promise: Promise<void>) => void
    requestMeta?: RequestMeta
  }
): Promise<void>
```

When invoking Node.js entrypoints directly, adapters can pass helpers directly on `requestMeta` instead of relying on internals. Some of the supported fields are `hostname`,
`revalidate`, and `render404`:

```ts
await handler(req, res, {
  requestMeta: {
    // Relative path from process.cwd() to the Next.js project directory.
    relativeProjectDir: '.',
    // Optional hostname used by route handlers when constructing absolute URLs.
    hostname: '127.0.0.1',
    // Optional internal revalidate function to avoid revalidating over the network
    revalidate: async ({ urlPath, headers, opts }) => {
      // platform-specific revalidate implementation
    },
    // Optional function to render the 404 page for pages router `notFound: true`
    render404: async (req, res, parsedUrl, setHeaders) => {
      // platform-specific 404 rendering implementation
    },
  },
})
```

Relevant files in the Next.js core:

- [`packages/next/src/build/templates/app-page.ts`](https://github.com/vercel/next.js/blob/canary/packages/next/src/build/templates/app-page.ts)
- [`packages/next/src/build/templates/app-route.ts`](https://github.com/vercel/next.js/blob/canary/packages/next/src/build/templates/app-route.ts)
- and [`packages/next/src/build/templates/pages-api.ts`](https://github.com/vercel/next.js/blob/canary/packages/next/src/build/templates/pages-api.ts)

## Edge runtime (`runtime: 'edge'`) (deprecated)

> The Edge Runtime is [deprecated](/docs/messages/edge-runtime-deprecated). New routes should use the Node.js runtime.

Edge entrypoints use the following interface:

```typescript
handler(
  request: Request,
  ctx: {
    waitUntil?: (prom: Promise<void>) => void
    signal?: AbortSignal
    requestMeta?: RequestMeta
  }
): Promise<Response>
```

The shape is aligned around `handler(..., ctx)`, but Node.js and Edge runtimes use different request/response primitives.

For outputs with `runtime: 'edge'`, Next.js also provides `output.edgeRuntime` with the canonical metadata needed to invoke the entrypoint:

```typescript
{
  modulePath: string // Absolute path to the module registered in the edge runtime
  entryKey: string // Canonical key used by the edge entry registry
  handlerExport: string // Export name to invoke, currently 'handler'
}
```

After your edge runtime loads and evaluates the chunks for `modulePath`, use `entryKey` to read the registered entry from the global edge entry registry (`globalThis._ENTRIES`), then invoke `handlerExport` from that entry:

```ts
const entry = await globalThis._ENTRIES[output.edgeRuntime.entryKey]
const handler = entry[output.edgeRuntime.handlerExport]
await handler(request, ctx)
```

Use `edgeRuntime` instead of deriving registry keys or handler names from filenames.

Relevant files in the Next.js core:

- [`packages/next/src/build/templates/edge-ssr.ts`](https://github.com/vercel/next.js/blob/canary/packages/next/src/build/templates/edge-ssr.ts)
- [`packages/next/src/build/templates/edge-app-route.ts`](https://github.com/vercel/next.js/blob/canary/packages/next/src/build/templates/edge-app-route.ts)
- [`packages/next/src/build/templates/pages-edge-api.ts`](https://github.com/vercel/next.js/blob/canary/packages/next/src/build/templates/pages-edge-api.ts)
- and [`packages/next/src/build/templates/middleware.ts`](https://github.com/vercel/next.js/blob/canary/packages/next/src/build/templates/middleware.ts)

## Go runtime (`runtime: 'go'`)

With experimental [`route.go`](/docs/app/api-reference/file-conventions/route-go) handlers, `output.filePath` identifies a native executable rather than a JavaScript module. Package it with the declared `assets` for the target operating system and architecture, preserving executable permissions and the asset destination paths.

The executable targets the build host's operating system and architecture, with CGO disabled. Build in an environment that matches the deployment runtime. Cross-compilation is not supported for Go routes.

Start the executable without arguments, set `PORT` to its assigned HTTP port, and use the packaged function directory as its working directory. Set `x-matched-path` from the selected output on every request, even when the process serves only one output. The value is the matched route's pathname without `basePath`, such as `/users/[id]` for a dynamic route, `/docs` for a static route, and `/` or `/index` for the root route. Send it as its UTF-8 bytes or percent-encoded: `/café` and `/caf%C3%A9` select the same output. As in the Next.js server, `/index` is read as `/`, a static path starting with `/index/` loses that prefix, and backslashes are read as slashes. A request whose header is missing, repeated, or names no Go output returns `404`. The executable differs from the Next.js server in these cases, which select no output:

- A value that is not valid UTF-8. Node replaces invalid bytes instead.
- A value that contains `?` or `#`. Node ignores everything from there on. Builds with an adapter fail for a Go route whose path contains either character.
- A value that contains an encoded `/` or `\` (`%2F`, `%5C`), or an invalid escape, unless the value is itself an output's `id`.
- A value whose raw and decoded readings name different outputs. Builds with an adapter fail for a Go route whose path is the percent-encoded spelling of another Go route's path.
- `.` and `..` segments, which Node resolves and no output `id` contains.

With `next start`, Next.js routes each request and sends the selected route's exact `id` in `x-matched-path`, after removing every value the client sent, and its executable looks up that `id` without this normalization.

> **Good to know:**
>
> The executable trusts `x-matched-path`. The platform must set it from its routing decision and remove every value the client sent, in any letter case, before forwarding a request, as Vercel does and as the Next.js server assumes in minimal mode. On a platform that forwards a client's `x-matched-path`, a client can select any Go output compiled into the executable, bypassing the platform's routing and authorization.

Adapter builds fail when `x-matched-path` cannot select a Go route as itself, such as `app/index/docs/route.go`, which would be read as `/docs`. Every build fails for a folder name that ends with a space or contains a control character, which a header cannot carry. `next dev` warns about both. The server listens on `0.0.0.0` so container and function ingress can reach it. The adapter owns network isolation. The adapter build's executable runs independently of the self-hosted Next.js server: it requires neither a private Next.js token nor a parent-owned stdin pipe.

For dynamic Go routes, forward the final destination URL after rewrites and proxy processing, including its query string and any `basePath`. For example, a request for `/alias?sort=asc` rewritten to `/users/123` must reach the Go server as `/users/123?sort=asc` so it can extract `id=123` for `/users/[id]`. For static Go routes, the adapter can also forward the original pathname and the resolved query. The handler's `r.URL` and `r.RequestURI` reflect what the adapter forwards. Development and self-hosted deployments pass the final destination URL.

All Go route outputs of an adapter build share one `filePath`. An adapter can run a shared process or reuse the executable in a separate process for each output. Select and authorize the output before forwarding a request. The process uses the selected handler even when another Go route would match the request pathname. For dynamic routes, it parses parameters for that handler only. Escaped slashes stay within their original parameter segments. A pathname with a malformed percent escape returns `400`. Dynamic routes also return `400` for a pathname that decodes to invalid UTF-8 and `404` for a pathname that does not match the selected route.

The platform routes requests to the correct Go function and runs its own rewrite and proxy integration. Node.js outputs continue to use their existing handler interface. JavaScript callbacks such as `ctx.waitUntil` cannot be passed to the Go process; the initial server contract provides no completion guarantee for post-response work.

---

For a semantic overview of all documentation, see [/sitemap.md](/sitemap.md)

For an index of all available documentation, see [/docs/llms.txt](/docs/llms.txt)