Skip to content

Bootstrapper quickstart

David Reed edited this page Nov 20, 2026 · 6 revisions

This page gets STomp running on your machine in a few minutes. First you run the demo to see what a finished host looks like. Then you build the smallest host of your own: a form, a search builder and a submit handler, the same three parts the 2022 bootstrapper quickstart had, on today's API.

If you already have a site or a server, Install into an existing app covers adding STomp to it. If you used TOMPBoot before, Migrating from TOMP maps the old calls to the new ones.

Requirements

  • Node.js 22 or newer. The package declares "engines": { "node": ">=22" }, and the demo server uses import attributes, which older Node versions refuse to parse.
  • npm, with access to github.com as well as the npm registry. The epoxy transport STomp uses is a patched build that npm downloads from GitHub. (git is only needed to clone the demo below.)
  • Chrome or another Chromium browser. STomp's test suites run in Chrome.
  • localhost or HTTPS. STomp runs in a service worker, and browsers only allow service workers in a secure context. localhost and 127.0.0.1 count as secure; a LAN address such as http://192.168.1.23:8080 does not.

Try the demo

The public demo is https://stomp.fracit.al. To run the same app locally:

git clone https://github.com/Fracital/powerMouse.git
cd powerMouse
npm install
npm run build
npm run demo

npm run build writes dist/, the files a host serves. npm run demo starts demo/server.js on http://localhost:8080 (set PORT to change it) with a holyWisp relay on /wisp/ and both transports. Open it, type example.com into the box and press Enter.

Two things about the local demo:

  • On http://localhost:8080 the demo runs in origin isolation mode and serves the proxied pages from http://127.0.0.1:8080, a second origin. On http://127.0.0.1:8080 it runs everything on one origin. Origin isolation explains the difference.
  • The demo also serves examples/minimal-host.html at http://localhost:8080/examples/minimal-host.html. It is a single page with one module script and a comment for each step, and the project's host API checks run against it.

The rest of this page builds a host without cloning the repository: everything comes from npm.

Build your own host

You will end up with this:

my-proxy/
├── package.json
├── server.js          Express: serves STomp, the transport, your page, and wisp
└── public/
    └── index.html     the form, the search builder and the submit handler

1. Create the project and install STomp

mkdir my-proxy && cd my-proxy
npm init -y
npm pkg set type=module
npm install -E @sysce/stomp@nightly express holywisp
npm install -E "@mercuryworkshop/epoxy-transport@$(npm view @sysce/stomp@nightly "devDependencies[@mercuryworkshop/epoxy-transport]")"

STomp is published as nightly builds under the nightly tag, with versions like 4.2.0-nightly.202611192242.ge5f74c5 (the version, the UTC build time, the commit). -E saves that exact version in package.json instead of a ^ range, so the next npm install does not move you to another nightly. Keep the version you tested with.

Always give the @nightly tag. Plain npm install @sysce/stomp installs 2.0.0 from 2023, a different program with the old StompBoot API.

The second command installs the epoxy transport at the exact commit that STomp version pins as a development dependency in its own package.json: a Fracital build with patches upstream epoxy lacks, listed in deploy/epoxy/README.md. For the nightly installed above it prints and installs github:Fracital/EpoxyTransport#4d5a277e0e7691e572633d829c17619c2ef647b3. If you pin a STomp version other than the newest nightly, put that version in place of nightly in both commands.

2. Write the server

server.js:

import { createServer } from 'node:http';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import express from 'express';
import { holyWisp } from 'holywisp';
import { stompPath } from '@sysce/stomp/path';

// the directory of a package's entry file (its dist/)
const distOf = (name) => dirname(fileURLToPath(import.meta.resolve(name)));

const wisp = new holyWisp();
await wisp.start(1);

const app = express();
app.use('/stomp/', express.static(stompPath));
app.use('/epoxy/', express.static(distOf('@mercuryworkshop/epoxy-transport')));
app.use(express.static('public'));

const server = createServer(app);
server.on('upgrade', (req, socket, head) => {
	if (req.url.startsWith('/wisp/')) wisp.route(req, socket, head);
	else socket.destroy();
});
server.listen(Number(process.env.PORT) || 8080, () =>
	console.log(`http://localhost:${server.address().port}/`),
);

It serves four things:

Path What Why
/stomp/ stompPath, the package's dist/ the service worker, the controller and every file they load at run time
/epoxy/ the epoxy transport's dist/ the module the controller imports to make real network connections
/ your public/ folder your page
/wisp/ (WebSocket) holyWisp the relay the transport tunnels TCP through to reach real sites

holyWisp starts its prebuilt server binary as a child process on a loopback port, and route() hands it each WebSocket upgrade. The child stops when Node exits. By default it refuses connections to loopback and private addresses, so a proxied page cannot reach your machine or your LAN through it.

3. Write the page

public/index.html:

<!doctype html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1" />
		<title>My proxy</title>
		<style>
			body {
				margin: 0;
				height: 100vh;
				display: flex;
				flex-direction: column;
				font: 14px system-ui, sans-serif;
			}
			#stomp-form {
				display: flex;
				gap: 4px;
				padding: 4px;
			}
			#stomp-input {
				flex: 1;
			}
			#stomp-frame {
				flex: 1;
				border: 0;
			}
		</style>
	</head>
	<body>
		<form id="stomp-form">
			<input
				id="stomp-input"
				placeholder="Search or enter web address"
				autocomplete="off"
			/>
			<button>Go</button>
		</form>
		<iframe id="stomp-frame" title="Proxied page"></iframe>

		<script type="module">
			import { StompController, SearchBuilder } from '/stomp/controller.mjs';

			const form = document.getElementById('stomp-form');
			const input = document.getElementById('stomp-input');
			const search = new SearchBuilder('https://duckduckgo.com/?q=%s');

			// Start the proxy once. The submit handler waits for it.
			const ready = (async () => {
				const directory = '/stomp/';
				const registration = await StompController.register(directory);
				const controller = new StompController({
					serviceworker: registration,
					transport: {
						module: '/epoxy/index.mjs',
						options: [{ wisp: location.origin.replace(/^http/, 'ws') + '/wisp/' }],
					},
					directory,
					onNavigate(info) {
						input.value = info.url;
						document.title = info.title || 'My proxy';
					},
				});
				await controller.wait();
				return controller.createFrame(document.getElementById('stomp-frame'));
			})();

			form.addEventListener('submit', async (event) => {
				event.preventDefault();
				const frame = await ready;
				frame.go(search.query(input.value));
			});
		</script>
	</body>
</html>

4. Run it

node server.js

Open http://localhost:8080, type example.com and press Enter. The frame shows the page, the input changes to http://example.com/ and the tab title to the page's title. Type a few words instead and the frame shows a DuckDuckGo search for them.

Run node server.js from the my-proxy folder: express.static('public') is resolved against the current directory.

What the page does

The script does the same five steps every STomp host does, in this order.

  1. StompController.register('/stomp/') registers /stomp/serviceWorker.js with the scope /stomp/ and resolves once the worker is activated (after 30 seconds at the most, so a stuck worker cannot hang your page). The service worker rewrites every proxied HTML, CSS and JavaScript response. Your page at / is outside that scope, and it does not need to be inside it: the controller only talks to the worker.
  2. transport is a descriptor: a module URL and the arguments for its constructor. The controller imports /epoxy/index.mjs in a dedicated worker (transportWorker.js from the directory) and runs new EpoxyTransport({ wisp }) there, off your page's main thread. The wisp URL is built from the page's own origin, so it is ws:// on http:// and wss:// on https://.
  3. new StompController({ ... }) ties the service worker and the transport together. directory is where dist/ is served and the worker's scope. It must be on your page's origin and end with a slash.
  4. await controller.wait() resolves once the service worker has accepted this controller.
  5. controller.createFrame(iframe) turns your <iframe> into a STomp frame and returns a Frame. frame.go(url) loads a real URL through the proxy. The frame's address becomes something like /stomp/kDqSTAdH/html/rffNfPYzd0_xQnlDqhsldqEiVA: the controller's id, the kind of resource, and the real URL sealed by the default xor codec.

onNavigate is called whenever the proxied page reports where it is: when it loads, on pushState, on hash changes and when its title changes. That is how the address bar follows the page without polling.

The submit handler waits for ready instead of assuming the proxy has started. A visitor can press Enter before the service worker is active, and the first search then waits for it. This is what await boot.ready did in the 2022 page.

The search builder

new SearchBuilder(template) turns what the user typed into a URL. query(input) follows three rules, in this order:

Input Rule query() returns
https://example.com/a starts with http:// or https:// the input unchanged
example.com, en.wikipedia.org/wiki/Proxy_server, localhost:3000 no spaces and a dot, or localhost with an optional port http:// plus the input
what is a proxy, what is 2.5 anything else the template with %s replaced by the URL-encoded input

Two consequences of these rules:

  • A bare host gets http://, not https://. Sites that only serve HTTPS redirect, which costs one extra request, and that first request is sent unencrypted.
  • The scheme test is case sensitive and only knows HTTP. HTTPS://EXAMPLE.COM becomes http://HTTPS://EXAMPLE.COM. Lower-case the scheme yourself if your users type in capitals.

The demo uses https://search.brave.com/search?q=%s. Any search page that takes the query in its URL works.

Next steps

Troubleshooting

"Your browser does not support service workers."

The page is not in a secure context, so navigator.serviceWorker does not exist. This is what you get on http://192.168.1.23:8080 even in Chrome. Use localhost, or serve the page over HTTPS.

"Failed to register a ServiceWorker for scope ('http://localhost:8080/stomp') with script ('http://localhost:8080/serviceWorker.js')"

The directory is missing its trailing slash. '/stomp' resolves file names against /, so the worker is looked for at /serviceWorker.js. Write '/stomp/'.

Pressing Enter reloads the page and nothing else happens

The module script never ran, so the submit handler was never added. Look at the console. A common cause is a server that sends .mjs files with a type other than JavaScript; nginx does this by default (see Install into an existing app).

The console warns about allow-scripts and allow-same-origin

The full warning is "An iframe which has both allow-scripts and allow-same-origin for its sandbox attribute can escape its sandboxing." It is expected. createFrame() gives the frame a sandbox attribute that includes allow-same-origin, because the service worker can only control a frame of its own origin. The sandbox stops <a target="_top"> and similar links from replacing your page; it is not isolation. Origin isolation is.

The frame shows your own server's 404 for a /stomp/<id>/html/... address

No controller is alive to answer it. A routed address works only while a host page with a controller is open. Opening it directly in a tab, or reloading it after its host page closed, reaches your server instead.

A search engine shows a block page or answers "429 Too Many Requests"

Sites see the IP address of the machine your wisp server runs on. Open the same search on that machine without STomp first. If it is refused there too, the block is about that IP, not about STomp. Brave Search answered 429 to a headless Chrome on the test machine both with and without STomp, which is why this page uses DuckDuckGo.

Clone this wiki locally