> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Handlers on Cloud Run

> Deploy a target handler as a Cloud Run service.

1. Write the [handler](https://docs.bijection.com/functions/targets.md#write-the-handler) and a server for
   it:

   ```ts server.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
   import { serve } from "@bijectionhq/target-handler/serve";
   import score from "./handlers/score";

   serve(score); // listens on $PORT
   ```

2. Build it for Node (for example
   `esbuild server.ts --bundle --platform=node --target=node22 --outfile=dist/server.js`)
   and add a `Dockerfile`:

   ```dockerfile theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
   FROM node:22-slim
   COPY dist/server.js /app/server.js
   CMD ["node", "/app/server.js"]
   ```

3. Set the token, then deploy the service with the same value and
   unauthenticated access. Bijection authenticates with the target's token,
   not with IAM:

   ```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
   bijection secret set scoring.score.token
   gcloud run deploy score --source . --allow-unauthenticated \
     --set-env-vars BIJECTION_TARGET_TOKEN=<the same value>
   ```

4. Bind the target to the service in the installation's bindings file, then deploy:

   ```ts bindings.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
   import { placement } from "@bijectionhq/bijection";
   import app from "./bijection/app";
   const { bind, endpoint, env, bindings } = placement;

   export default bindings([
     bind(app.scoring.score, endpoint({
       url: env("SCORING_URL"), hosts: ["score-<hash>.run.app"], credential: "scoring.score.token",
     })),
   ]);
   ```

   Set `SCORING_URL` with `bijection env set SCORING_URL <url>` before deploying. Replace the example host with the exact host returned by your provider.

One server can serve several targets. Pass
`serve({ "scoring.score": score, "scoring.explain": explain })` and give each
target its own path: `https://…/scoring.score`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.