Skip to content

Lightweight native Discord client for Windows, Linux and macOS, written in Rust. No Electron, no browser engine.

1.1 KB
Raw Blame
// The registry on your own machine, for trying RustCord against it:
//
//   node server/dev.mjs            (http://127.0.0.1:8787, rows kept in memory)
//   set RUSTCORD_REGISTRY_URL=http://127.0.0.1:8787   then start RustCord
//
// Rows are gone when it stops. PORT changes the port.

import { createServer } from "node:http";
import { handle, memoryStore } from "./registry.mjs";

const store = memoryStore();
const port = Number(process.env.PORT) || 8787;

createServer(async (req, res) => {
  const chunks = [];
  for await (const chunk of req) chunks.push(chunk);
  const body = Buffer.concat(chunks);
  const request = new Request(`http://127.0.0.1:${port}${req.url}`, {
    method: req.method,
    headers: req.headers,
    body: req.method === "GET" || req.method === "HEAD" ? undefined : body,
  });
  const response = await handle(request, store);
  res.writeHead(response.status, Object.fromEntries(response.headers));
  res.end(await response.text());
  console.log(`${req.method} ${req.url} -> ${response.status} (${store.rows.size} rows)`);
}).listen(port, "127.0.0.1", () => console.log(`RustCord registry (dev) on http://127.0.0.1:${port}`));