weft
ir 2.6.0 · warp 1.8.0
Part four · Step 17 of 19

Ports, config and deployment

A port is a capability bound at the edge of the application, and a config file exists to bind them.

Goal

Bind the store, the clock and the rate limiter your shop has been using implicitly, and deploy the result to somewhere that is not your laptop.

Your shop has been running on defaults: an in-process store, a cookie session, and inline as the only executor. Every one of those is a port — a capability the kernel asks for by name — and weft.config.ts is the one file whose job is to bind them. A first application binds none, which is why you have not needed the file until now.

1 · Bind them

sketch — not compiled
// weft.config.ts
import { bySession, defineConfig, redisLeases } from '@weftjs/core'

export default defineConfig({
  port: 4173,
  store: redisLeases(process.env.REDIS_URL!),
  limits: { counted: bySession('sid') },
  authority: { grants: { anonymous: ['cart:add'] } },
})

Each line answers something the kernel refuses to guess. What a call is counted against is the clearest of them: a deployment behind a CDN counts by address, one where every caller has a subject counts by subject, and nothing in your application knows which of those it is behind. Delete the grant and every add becomes E_CAPABILITY_DENIED with the missing capability named — the framework refuses, and the config is where the answer lives.

2 · Deploy the tier you built

sketch — not compiled
npx weft build
npx weft upload --to s3://shop-static   # the L0 pages: files, no kernel
npx weft start                          # the rest, wherever you run Node

The pages the build resolved are objects in a bucket and never reach your server. What is left is the part that genuinely varies per request, which on this shop is the cart and the feed.

Ports, config, and the build lists every port, what binds it, and what each adapter can and cannot promise.