> For the complete documentation index, see [llms.txt](https://docs.serverlessapigateway.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.serverlessapigateway.com/recipes/service-vs-service-binding/service-local-entrypoints.md).

# Service Integrations with Local Entrypoints

Use local services when the gateway and the handler should ship together in one worker project. The `services` array defines local module entrypoints that the gateway imports at startup. This pattern keeps related code co-located and avoids the overhead of a separate Worker deployment.

**Last reviewed:** 2026-03-06

## When to use this

Use the service execution recipes when your routes need to call Worker code directly instead of proxying to an external HTTP endpoint. The gateway supports two patterns: local service modules bundled with the worker, and service bindings that call separately deployed Workers via Cloudflare bindings.

## Key concepts

* The `service` integration type imports a local JavaScript module from the worker project and calls its default export. The module ships in the same worker bundle.
* The `service_binding` integration type calls a separately deployed Worker through a Cloudflare service binding. The target Worker must be deployed independently and bound in `wrangler.toml`.
* Pre-process hooks run before the main integration and can short-circuit the request by returning a response. Use them for custom authorization, input validation, or request enrichment.
* Post-process hooks run after the main integration returns and can modify the response. The Auth0 callback post-process hook is the most common use case.
* When choosing between proxy and service execution, consider latency (service bindings avoid an external HTTP round-trip) and coupling (proxy keeps the backend independently deployable).

## Repo-grounded example

```json
{
  "services": [
    { "alias": "worker1", "entrypoint": "./services/endpoint1" }
  ],
  "paths": [
    {
      "method": "GET",
      "path": "/service",
      "integration": {
        "type": "service",
        "binding": "worker1"
      }
    }
  ]
}
```

This snippet defines a `services` array with one local entrypoint at `./services/endpoint1`. The `integration.binding` field references the service alias, and the gateway calls the module's default export when a request matches this path.

## Troubleshooting

* If a `service` integration returns 500, confirm that the entrypoint path in the `services` array matches the actual file location relative to the worker root and that the module exports a default function.
* If a `service_binding` integration returns a binding error, verify that the binding name in config matches the binding declared in `wrangler.toml` and that the target Worker is deployed.
* If a pre-process hook does not short-circuit as expected, check that the hook function returns a `Response` object -- returning `undefined` or `null` lets the request continue to the main integration.
* If post-process hooks are not running, confirm the hook config uses the correct `binding` and `function` field names and that the hook Worker is deployed and bound.

## Related docs

* [service binding](/configuration/service-binding.md)
* [servers](/configuration/servers.md)
* [gateway troubleshooting matrix](/troubleshooting/wrangler-deploy-guide/gateway-troubleshooting-matrix.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.serverlessapigateway.com/recipes/service-vs-service-binding/service-local-entrypoints.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
