net
tcmts.dev.devenv.net · #zh2o3nd2 · mjs file
// A local AT Protocol network from Bluesky's own software (@atproto/dev-env): a PLC directory and a PDS (with its
// OAuth server), two accounts, and a "directory" front for tcm's TCM_ATPROTO_DIRECTORY: DID documents from the PLC,
// handles from the PDS (com.atproto.identity.resolveHandle), as DNS would answer them for real handles. Writes what
// it made to env.json, beside it.
import { TestNetworkNoAppView } from '@atproto/dev-env'
import fs from 'node:fs'
import http from 'node:http'
const net = await TestNetworkNoAppView.create({})
const agent = net.pds.getAgent()
const accounts = {}
for (const [handle, password] of [['alice.test', 'alice-pass'], ['maya.test', 'maya-pass']]) {
const r = await agent.com.atproto.server.createAccount({ handle, email: `${handle}@example.com`, password })
accounts[handle] = { did: r.data.did, password }
}
const front = http.createServer(async (req, res) => {
const url = new URL(req.url, 'http://x')
const target = decodeURIComponent(url.pathname).startsWith('/did:') ? net.plc.url : net.pds.url
const r = await fetch(`${target}${url.pathname}${url.search}`, { method: req.method })
res.writeHead(r.status, { 'content-type': r.headers.get('content-type') ?? 'application/json', 'access-control-allow-origin': '*' })
res.end(Buffer.from(await r.arrayBuffer()))
})
await new Promise((r) => front.listen(0, '127.0.0.1', r))
const env = { plc: net.plc.url, pds: net.pds.url, directory: `http://127.0.0.1:${front.address().port}`, accounts }
fs.writeFileSync(new URL('./env.json', import.meta.url), JSON.stringify(env, null, 2))
console.log(JSON.stringify(env, null, 2))
process.on('SIGTERM', async () => {
await net.close()
process.exit(0)
})
used by