Website and Message Router source code for the Multiplayer Doom on Cloudflare Workers tech demo
This repo contains two Workers
Assets are in ./assets
Worker code is in site/index.js
You need the following files in ./assets
(not included in this repo):
npm install -g @cloudflare/wrangler@beta
wrangler login
wrangler publish --config wrangler-site.toml
Adjust wrangler-site.toml to your account_id
and zone_id
.
Our message router has the following requirements:
Just supports the network multiplayer in our Silent Space Marine showcase project.
Read more about it in our blog post here.
The router source code is at router/index.mjs
First make sure you have Durable Objects enabled in your account.
Make sure you have the Durable Objects wrangler (beta) installed:
npm install -g @cloudflare/wrangler@beta
Adjust wrangler-router.toml to your account_id
and zone_id
or use the CF_ACCOUNT_ID
and CF_ZONE_ID
environment variables.
Run this command just once
wrangler login
wrangler publish --config wrangler-router.toml --new-class Router
Later updates use:
wrangler login
wrangler publish --config wrangler-router.toml
You can use make
to deploy the workers.
Create an .env
file with your account and zone ids:
ROUTER_CF_ZONE_ID = 72...........91
ROUTER_CF_ACCOUNT_ID = 0a...............2f
SITE_CF_ZONE_ID = 13....................a0
SITE_CF_ACCOUNT_ID = 07.................4f
Run make
:
make publish
You can run the Website, Wasm Doom and Multiplayer locally, in your computer, using a NodeJS WebSocket router implementation.
First install NodeJS and npm. Then:
cd scripts
npm install
./router.js
Point your browser to http://0.0.0.0:8000
Read more about Multiplayer Doom on Cloudflare Workers in our blog post here.