Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
@carbon/serve
The HTTP server a self-hosted ERP or MES runs on (apps/*/server/node.ts,
which is what pnpm start runs in the image). Fastify in front, React Router
behind. Vercel does not use it; it calls apps/*/server/app.ts.
It replaces react-router-serve, which loads the build itself and takes no
options, so nothing could be put between a request and React Router.
Always
- TypeScript that
nodecan run as it is. The image has no TypeScript toolchain; Node 22 strips the types. So only erasable syntax (no enums, no parameter properties),import typefor types, and file extensions on relative imports. It must stay outsidenode_modules: Node refuses to strip types there, andpackages/is copied into the image as it is. - The app's own URL is the allowed origin.
serve({ siteUrl })adds that host to React Router'sallowedActionOriginsat runtime. React Router refuses a form submit whoseOriginis not the origin ofrequest.url, and behind a proxy that ends TLS the app is called over http while the browser says https — without this every submit is a 400. ERP passesERP_URL, MESMES_URL. Unset, nothing is added. - Static files are sent as the build left them. A build (see
precompressedAssetsin@carbon/dev/vite; every production build but Vercel's) writes a.brbeside each asset and keeps the original. The.brgoes as it is to anything that accepts Brotli; the original to a caller that does not. Both answers carryVary: Accept-Encoding. - Files are read once, at start (
src/assets.ts). Every Brotli copy, and every uncompressed file up to 1 MB that has none, is held in memory with its headers already made; serving one is a lookup and a write. Read per request, each cost a stat, an open and a stream on libuv's four threads — the same four that compress rendered pages. Larger files, and the original of a compressed one for a caller that refuses Brotli, are sent from disk byreply.sendFile, which answers ranges. Nothing here may read a file while handling a request. /assets/*and/_vercel/*are routes of their own. A file or a plain 404, never a rendered page.- React Router is a route, not the not-found handler.
@fastify/compressattaches to routes only; from the not-found handler pages went out uncompressed. - Bodies are left unread. The content-type parsers are removed so the request stream reaches React Router whole.
- The request URL is joined as text, never resolved against a base: a
path of
//other.host/xwould name another host, and React Router checks a form'sOriginagainst that URL.@mjackson/node-fetch-serverresolves, which is whysrc/request.tsis ours. - Fastify's defaults are not all kept.
keepAliveTimeoutis above any proxy's idle timeout, andrequestTimeoutis Node's 300s (Fastify sets none).bodyLimitdoes not apply: no body is parsed here. A request whoseContent-Typeis not a media type at all is a 415 from Fastify before React Router sees it. - What a library already answers is left to it.
negotiatorreadsAccept-Encoding(abr;q=0is a refusal),@fastify/sendnames a file's content type — the same code that sends the original, so both copies of an asset are called one thing — andclose-with-graceshuts the server down: requests in flight finish, bounded at twenty seconds. - Routes that should not go through React Router at all belong here, in front of the catch-all — not as a path check inside a route.
Never
- Compress a client asset per request. That is what the build step replaced.
- Trust
X-Forwarded-*to decide the origin. The deployment's configured URL is the answer; a header is whatever the last hop sent. - Send the caller an error's message. It is logged; the answer is the status.
Validation
pnpm --filter @carbon/serve test
pnpm --filter @carbon/serve typecheck