# ServerSiteGateProvider

## Import

```typescript
import { ServerSiteGateProvider } from "alepha/server";
```

## Overview

The site gate: the whole site behind HTTP basic auth, turned on by the
environment alone.

- `SITE_GATE_USERNAME` and `SITE_GATE_PASSWORD` both set: on.
- Neither: off, and this provider does nothing.
- Only one: the app refuses to start, since a gate half configured is a
  gate someone believes is on.

No primitive to declare: the app's code is the same in every environment,
and a hosted copy (a staging, a demo) is protected by setting two variables
and redeploying, with no rebuild.

## What it does

- Registers one check on every route (`/*`), SSR pages and `$serve` static
  files included.
- Accepts `Authorization: Basic`, or `x-site-gate: <username>:<password>` for
  a script whose `Authorization` carries a bearer token. Either is removed
  from the request once checked, so the app's own authentication never sees
  it.
- Once passed, sets a gate cookie (`HttpOnly`, `Secure`, `SameSite=Lax`,
  signed with a key derived from `SITE_GATE_PASSWORD` and `APP_SECRET`), so
  a browser is not asked again and a password change voids every cookie.
  `pass` sets it from a module that admitted a visitor another way.
- Leaves open the prefixes modules declare with `allow`: the health
  probes `/health`, `/healthz`, `/readyz` and `/livez` by default, since a
  supervisor probing a protected copy has no password. `/version` stays
  gated.

## Limit on Cloudflare Workers

A Worker serves the files of `dist/public` (bundles, images and prerendered
pages) from Cloudflare's asset layer before the worker runs, so the gate
covers what the worker serves (server-rendered pages, API, `$serve` routes)
and those files stay public.
