Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion examples/prompt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
// Define the port to listen on
const PORT = 3000;

// Cache for verification keys to improve performance
let verificationKeysCache = { id: "", keys: [] };

// Define the handler function
async function handler(request, response) {
console.log(`Received [${request.method}] to [${request.url}]`);
Expand All @@ -36,15 +39,18 @@ async function handler(request, response) {
const keyID = String(request.headers["github-public-key-identifier"]);

try {
const { isValidRequest, payload } = await verifyAndParseRequest(
const { isValidRequest, payload, cache } = await verifyAndParseRequest(
body,
signature,
keyID,
{
token: tokenForUser,
cache: verificationKeysCache,
},
);

verificationKeysCache = cache;

if (!isValidRequest) {
console.error("Request verification failed");
response.writeHead(401, { "Content-Type": "text/plain" });
Expand Down