# Write your own preset

A host without a preset gets one from a file or a package of your own. Write it with [`definePreset`](/api-reference/kit#definepreset-preset-presetcontext) of `hamur/kit` and name it in the config, `preset: "./presets/my-host.ts"` (resolved from the project root), or with `--preset ./presets/my-host.ts`. A package name works the same way when the package default-exports the preset. It is never detected from the environment, but `HAMUR_PRESET` may name its path. `hamur.json` records the path or package as `presetSource`, and `hamur preview` loads the preset from it again. `hamur generate` builds it when it has `prerender`, else `static`. `tasks.runOnStart` needs `lifetime: "process"` and `startup: "load"`, and the drivers that run on every preset run on yours; `fs`, `sqlite`, `redis` and the platform drivers follow its traits.

The preset says how the server runs and when, and Hamur follows it: `lifetime: "request"` flushes logs and spans after each request, for a function that may freeze after it answers; `startup: "load"` runs the server plugins when the module loads, `"request"` at the first request; `ownsProcess: true` lets a bad environment end the process with exit code 1. `runtime` is `event.runtime.name`, `serverTarget` the bundle target and `entry` the module that wraps the app handler for the host. `features` says which features the host runs. `finalize(ctx)` runs after the build and writes what the host reads, from `ctx.serverEntry`, `ctx.publicFiles`, `ctx.prerendered`, `ctx.routeRules` and `ctx.functions`. A missing field fails when the config loads, naming the file: `Preset "./presets/my-host.ts" has no entry`.

````ts [api/kit-define-preset.ts]
import { writeFile } from "node:fs/promises"
import { join } from "node:path"
import { fileURLToPath } from "node:url"
import { definePreset } from "hamur/kit"

export default definePreset({
  name: "my-host",
  runtime: "my-host",
  serverTarget: "node",
  lifetime: "process",
  startup: "load",
  ownsProcess: true,
  entry: fileURLToPath(new URL("./entry.ts", import.meta.url)),
  features: {
    websockets: "unsupported",
    pubsub: "unsupported",
    streaming: "stable",
    metrics: "stable",
    imageTransforms: "unsupported",
    envSecrets: "stable",
    durableObjects: "unsupported",
  },
  async finalize(ctx) {
    const manifest = {
      entry: ctx.serverEntry,
      files: ctx.publicFiles,
      pages: ctx.prerendered.map((page) => page.path),
      functions: ctx.functions,
    }
    await writeFile(join(ctx.options.outputDir, "my-host.json"), `${JSON.stringify(manifest, null, 2)}\n`)
  },
})
````
