1
2
3
4
5
6
7
8
9
10
11
12
13
import { randomBytes } from "node:crypto";
export const generateSecret = (req: Request) => {
let length = new URL(req.url).searchParams.get("length");
if (!length || isNaN(+length)) {
length = "32";
}
const secret = randomBytes(+length).toString("hex");
return Response.json({ secret });
};