# {{projectName}} / {{appName}}

A library of standalone serverless functions (template: **edge-functions**).
Each `functions/*.serverless.ts` is bundled + deployed on its own — there is
no long-running server here and no dev port.

## The functions

| File | Method | Demonstrates |
|---|---|---|
| `health.serverless.ts` | GET | simplest diagnostic; `ctx.env`; pure `Effect.sync` |
| `shareLink.serverless.ts` | POST | pure compute; runtime hints (memory/timeout/region) |
| `geoGreeting.serverless.ts` | GET | reading `ctx.request.headers` (edge geo) |
| `slackNotify.serverless.ts` | POST | `ctx.waitUntil` — background work after the response |
| `currencyConvert.serverless.ts` | POST | outbound HTTP via `HttpClient`; read + transform JSON |
| `verifySignature.serverless.ts` | POST | Web Crypto HMAC; `ServerlessHttpError` 401 |
| `aiComplete.serverless.ts` | POST | a third-party API needing a secret (`ctx.env`); 502 mapping |
| `resolveLink.serverless.ts` | GET | a lookup; 404 via `ServerlessHttpError` |

Every function is **edge-safe** (no `node:*`), so the same code runs on
Cloudflare Workers, Scaleway Functions, and your own node box.

## Run one locally

```bash
pnpm install
voltro serverless list .                                   # what's here
voltro serverless dev functions/health.serverless.ts       # one function on :8910
curl http://localhost:8910/

# functions that need config read it from the env:
SLACK_WEBHOOK_URL=https://hooks.slack.com/... \
  voltro serverless dev functions/slackNotify.serverless.ts
```

`voltro serverless serve .` runs ALL of them at once (each mounted at
`/<name>`) — handy as a single self-hosted sidecar.

## Deploy

```bash
voltro serverless build .                                  # bundle all → inspect
voltro serverless deploy --target node                     # self-host kit (Dockerfile + README)
voltro serverless deploy --target cloudflare               # Cloudflare Workers
voltro serverless deploy --target scaleway --namespace-id <id>   # Scaleway Functions
```

Set each function's secrets at deploy time (the host's env / secret store):
`SLACK_WEBHOOK_URL`, `SIGNING_SECRET`, `OPENAI_API_KEY`, `SHARE_BASE_URL`, …

## Add your own

Drop a new `functions/<name>.serverless.ts` exporting
`export default defineServerless({ … })`. It's discovered automatically — no
registry, no config.
