#!/usr/bin/env node import { TestNetworkNoAppView } from "@atproto/dev-env"; const plcPort = Number(process.env.PLC_PORT ?? 2582); const pdsPort = Number(process.env.PDS_PORT ?? 2583); const network = await TestNetworkNoAppView.create({ plc: { port: plcPort }, pds: { port: pdsPort, hostname: "localhost" }, }); console.log(`dev-pds: PLC directory at ${network.plc.url}`); console.log(`dev-pds: PDS at ${network.pds.url}`); // Tranquil PDS, which pds.starhaven.dev runs, answers whether an email // address has an account, for sign-up. This PDS doesn't, so it's added here, // in front of every other route. const server = network.pds.server.server; const [app] = server.listeners("request"); server.removeAllListeners("request"); server.on("request", async (req, res) => { if (req.method !== "POST" || !req.url.startsWith("/xrpc/_account.checkEmailInUse")) { return app(req, res); } let body = ""; for await (const chunk of req) body += chunk; const { email } = JSON.parse(body); const account = await network.pds.ctx.accountManager.getAccountByEmail( email.trim().toLowerCase(), ); res.setHeader("content-type", "application/json"); res.end(JSON.stringify({ inUse: account !== null })); }); const seed = network.getSeedClient(); const account = await seed.createAccount("alice", { handle: "alice.test", email: "alice@dev.test", password: "hunter2", }); console.log(`dev-pds: default account ${account.handle} (${account.did}), password "hunter2"`); const shutdown = () => network.close().then(() => process.exit(0)); process.on("SIGINT", shutdown); process.on("SIGTERM", shutdown);