# Nuxt

> Mount the pipedog WebRTC offer endpoint in a Nuxt (Nitro) server route.

Source: https://polvallverdu.github.io/pipedog/docs/frameworks/nuxt/



A Nitro server route handles `POST /api/offer`. The `.post.ts` suffix limits it to POST.
`toWebRequest` turns the h3 event into a web `Request` for `offer`.

## Install [#install]

```bash
bun add @pipedog/core @pipedog/asyncio @pipedog/transport-smallwebrtc @pipedog/transport-websocket @pipedog/serializer-protobuf @pipedog/openai @pipedog/audio-silero @pipedog/audio-smart-turn
```

`@pipedog/audio-smart-turn` isn't imported anywhere: the default turn strategies load it. To run
the snippet from a checkout instead, see [Installation](https://polvallverdu.github.io/pipedog/docs/installation/#from-source).

## Files [#files]

The endpoints come from the shared module on the [overview](https://polvallverdu.github.io/pipedog/docs/frameworks/#the-two-endpoints).
`~/server/utils/voice` re-exports it:

```ts title="server/utils/voice.ts"
export { offer, runSocketAgent, socket } from "../../../shared/voice.ts";

```

```ts title="server/api/offer.post.ts"
import { offer } from "~/server/utils/voice";

// Nitro's Node, Bun or Deno preset: the media runs over UDP, so a serverless
// preset won't carry it. `toWebRequest` is auto-imported from h3.
export default defineEventHandler((event) => offer(toWebRequest(event)));

```

Nuxt auto-imports `defineEventHandler` and `toWebRequest`, so the handler doesn't import them. The
snippet ships `server/auto-imports.d.ts` so it typechecks without a Nuxt project. A Nuxt app
generates those declarations itself.

## Run it [#run-it]

```bash
OPENAI_API_KEY=sk-... bunx nuxt dev
```

The browser then POSTs its SDP offer to `/api/offer`.

## Deploy [#deploy]

Use a Nitro preset that runs a Node, Bun or Deno server, such as `node-server` (the default),
`bun` or `deno-server`. The serverless presets don't carry the UDP media.

## WebSocket [#websocket]

This snippet mounts only the offer. Nitro has its own WebSocket handlers, which this snippet doesn't
use. To serve WebSocket sessions, run a [Bun](https://polvallverdu.github.io/pipedog/docs/frameworks/bun.md) or [Deno](https://polvallverdu.github.io/pipedog/docs/frameworks/deno.md)
server next to the Nuxt app, or serve `socket` with `serveFetch()` from
`@pipedog/transport-websocket/serve`, which upgrades on Node, Bun and Deno.

## Authentication [#authentication]

The route has no auth. Wrap `offer` with a session check before it runs, as in
[Authentication](https://polvallverdu.github.io/pipedog/docs/frameworks/#authentication). A Nitro server middleware works too.
