GNU/Linux xterm-256color bash 614 views

Deployment: https://paste.chadig.com

GitHub: https://github.com/publicdomainrelay/atprotobin

cat << 'EOF' > backend_github_query.js
let text = "";
const decoder = new TextDecoder();
for await (const chunk of Deno.stdin.readable) {
  text += decoder.decode(chunk);
}
const input = JSON.parse(text);

const resp = await fetch("https://api.github.com/users/" + input["user"], {
  headers: {
    accept: "application/json",
  },
});

console.log(JSON.stringify(await resp.json()));
EOF

id=$(curl -sfX POST -F 'file=@backend_github_query.js' https://paste.chadig.com | jq -r .id)
curl -sfX POST -d '{"user": "publicdomainrelay"}' "https://paste.chadig.com/${id}" | jq

TODO:

// env -i "PATH=$PATH" deno run --allow-read=/tmp/hono-app.sock --allow-write=/tmp/hono-app.sock --allow-env --no-prompt app.ts
// curl --unix-socket /tmp/hono-app.sock http://localhost/jwk | jq
import { Hono } from "npm:hono";
import { decode } from "npm:cbor-x@1";

const app = new Hono();
const socketPath = "/tmp/hono-app.sock";

app.get("/jwk", async (c) => {
  const keyPair = await crypto.subtle.generateKey(
    { name: "ECDSA", namedCurve: "P-256" },
    true,
    ["sign", "verify"]
  );
  const jwk = await crypto.subtle.exportKey("jwk", keyPair.publicKey);
  return c.json({ success: true, jwk });
});

app.post("/cbor", async (c) => {
  // Read the raw binary body directly from the request
  const body = await c.req.arrayBuffer();

  if (body.byteLength === 0) {
    return c.json({ error: "Empty body" }, 400);
  }

  try {
    const parsedData = decode(new Uint8Array(body));
    return c.json({ success: true, parsed: parsedData });
  } catch {
    return c.json({ error: "Invalid CBOR payload" }, 400);
  }
});

try {
  Deno.removeSync(socketPath);
} catch (err) {
  if (!(err instanceof Deno.errors.NotFound)) throw err;
}

const server = Deno.serve({ path: socketPath }, app.fetch);
console.log(`Hono server listening strictly on Unix socket: ${socketPath}`);

Deno.addSignalListener("SIGINT", async () => {
  console.log("\nShutting down...");
  await server.shutdown();
  Deno.removeSync(socketPath);
  Deno.exit(0);
});