Artifact Share

Single-file HTML, published to a link

Drop in an HTML file. Get a link anyone can open.

AI coding tools produce self-contained HTML all day long — dashboards, reports, prototypes. Sending them means emailing files that render as raw markup or not at all. This turns one into /q3-forecast and keeps that link stable forever, even after you replace what it points to.

Sign-up is closed by an email allowlist — it is a personal tool. The architecture below is the part worth reading.

The whole design is one decision

Hosting HTML you did not write is hosting JavaScript you did not write. Everything else follows from where that code is allowed to run.

Deployment one

artifact-share

The dashboard. Sessions, uploads, versions. Holds the only cookie in the system, host-only and HttpOnly.

Deployment two

artifact-view

The public viewer. Two routes, no auth, no cookies, no client JavaScript of its own. Streams the stored file so the link stays canonical.

Both read one Postgres database and one blob store. The separation is at the origin, which is where the browser enforces it — not in the data layer, where it would be a convention nobody checks.

Two origins, not one

Published pages are arbitrary JavaScript. Served from the dashboard's origin, any of them could read the session cookie and call the dashboard API as the owner. Splitting the viewer into a second deployment hands that problem to the browser's own origin boundary.

A rejected alternative, on the record

One project serving the HTML under CSP: sandbox would isolate it just as well. It was rejected because opaque origins throw on localStorage, which generated artifacts use constantly. It would have silently broken much of what this exists to host.

The HTML is never sanitised

No script stripping, no rewriting, no restrictive CSP, no X-Frame-Options. Artifacts pull React, D3 and Chart.js from CDNs, and embedding them is a feature. Isolation comes from the origin split, not from filtering content.

Versions are append-only

Re-uploading to a slug adds a version; the old one stays readable at /slug/v/1. Restoring an old version publishes a copy forward rather than moving a pointer backwards, so the log only ever grows.

Stack

A pnpm workspace: two Next.js applications and one shared database package, deployed as two projects from a single repository.

Next.js 16
App Router, React 19, two apps
TypeScript
strict, no implicit any
Auth.js v5
Google OAuth + argon2id credentials
Drizzle ORM
typed schema, generated migrations
Neon Postgres
serverless, one database, two consumers
Vercel Blob
HTML bodies, public-read
Tailwind CSS
shadcn/ui component conventions
Playwright + Vitest
23 acceptance, 95 unit

Three bugs worth describing

Each was caught by a check that existed before the bug did. That is the argument for writing the checks.

  1. 01Every share reported “0 versions”

    Caught by an acceptance test

    Drizzle does not qualify column references inside a select-list template, so a correlated subquery compiled to `where "share_id" = "id"` and compared the versions table to itself. Replaced with a typed join and a group-by.

  2. 02Half the reserved-slug list was unreachable

    Caught by a live API probe

    Slug normalisation strips the characters that define the reserved names, so `_next` became the perfectly ordinary `next`, and `robots.txt` could never match at all. The check now runs against the raw input as well.

  3. 03A hosted page could publish as the owner

    Caught by measuring, not reading

    A multipart POST carries no custom headers, making it a CORS simple request: no preflight, so the browser sends it and only the response is hidden. The write still landed. The upload endpoint now verifies the Origin header.

Acceptance tests are numbered to match the specification, so a requirement maps to the test that proves it.

What happens on upload

  1. 01

    Size first

    Rejected from the Content-Length header before the body is read into memory.

  2. 02

    Sniff the bytes

    The first kilobyte must look like a document. A PNG renamed .html is refused; a .txt containing markup is accepted.

  3. 03

    Resolve a name

    Normalised as you type, checked against reserved routes, or generated as adjective-noun-NN.

  4. 04

    Store the body

    Written to blob storage under an unguessable path, then recorded in a transaction that cleans up after itself on failure.

  5. 05

    Skip duplicates

    Re-uploading identical bytes returns the existing version instead of spamming the log.

  6. 06

    Serve it back

    The viewer streams the file so the slug never redirects, with revalidating cache headers so a replacement is visible immediately.