# Netlify

The build writes `dist/`, the folder to publish, with `_headers` and `_redirects`, and a self-contained function in `.netlify/v1/functions/server/`: `server.mjs` and `app/`, a copy of `.output/server/`, so the function needs nothing else from the project. Files win over the function. Set the publish directory to `dist`. Hamur writes no `netlify.toml`, and removes the `.netlify/functions-internal/server.mjs` an older build left.

## Reference

|                      |                      |
| -------------------- | -------------------- |
| Preset               | `netlify`            |
| Runs on              | Netlify              |
| `event.runtime.name` | `netlify`            |
| Server target        | `node`               |
| Lifetime, startup    | `request`, `request` |

### Output

```text
dist/                       the publish directory
  _headers, _redirects       from your route rules
  ...                        the public files and /_hamur/
.netlify/v1/functions/server/
  server.mjs
  app/                       a copy of .output/server/
```

### Config keys

| Key                 | Default | What it does                                                                                                                 |
| ------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `netlify.edge`      | `false` | `true` is the same as `--preset netlify-edge`                                                                                |
| `netlify.functions` | `{}`    | merged into the function's `config` in `server.mjs`: `region`, `memory`, `vcpu`; `path` and `preferStatic` stay the preset's |
| `cdnPurge.netlify`  | unset   | purges tags and paths through Netlify; see [Caching and ISR](/caching-and-isr)                                               |

### Detection

The build selects it when `NETLIFY` is set, unless `--preset`, `preset` or `HAMUR_PRESET` names another. It is a row of the one table of markers in [Choosing a preset](/deploy#choosing-a-preset).

### Deploy command

`hamur deploy` builds, then runs `netlify deploy --no-build --dir dist --prod`; with `--preview` it runs `netlify deploy --no-build --dir dist`. See [`hamur deploy`](/deploy/platforms/hamur-deploy). The preview command of the preset, which `hamur preview` runs or prints, is `netlify dev --dir dist`.

### Limits

- Runs: streamed answers, private `app/env.ts` entries read at run time.
- Does not run: WebSockets and `server.syncedState`, `server.pubsub`, `server.metrics`, image transforms at run time, Durable Object classes.
- Platform image service: `netlify` (what `provider: "auto"` picks).
- `scheduledTasks` run as scheduled functions; `tasks.queue` and `tasks.runOnStart` do not apply. The request body limit is 6 MB.

The levels are the `features` of the preset: `hamur build` warns or fails when the app uses a feature the preset does not run (see [Preset features](/deploy#preset-features)).

`netlify.functions` in the config is merged into the function's `config`, for example `netlify: { functions: { region: "fra", memory: "2gb" } }`. `path` and `preferStatic` stay Hamur's. Netlify takes only literal values there, so the build writes the merged object into `server.mjs` as JSON. A value that is not an object fails when the config loads. Synchronous execution stops at 60 seconds on Netlify, whatever the config says.

`getRequestIP(event)` returns Netlify's `context.ip`.

A `function` route rule writes a function file for each distinct setting, `.netlify/v1/functions/hamur-fn-<hash>.mjs`, which serves the same app with `config.path` set to the rule's patterns (`/api/export/**` is `/api/export` and `/api/export/*`). `memory` is written as `memory` and the first of `regions` as `region`; `maxDuration` is not read, since Netlify's 60 seconds cannot be raised, and the build warns: `function.maxDuration is not read on the netlify preset (route rule "/api/export/**")`. See [Route rules](/route-rules#function-rule).

`netlify.config.images` in the config is written to `.netlify/v1/config.json` as `images`, for example `netlify: { config: { images: { remote_images: ["^https://cdn\\.example\\.com/.*$"] } } }`. `@hamur/image` writes `images.remote_images` there for its `netlify` provider and its keys win. The file is written only when `images` is not empty. `netlify.config` that is not an object fails when the config loads.

````sh [deploy-netlify.sh]
hamur build --preset netlify
netlify dev --dir dist
````
