Skip to content

Commit

Permalink
feat: add cache control settings so the API key response is no longer…
Browse files Browse the repository at this point in the history
… cached
  • Loading branch information
lukeocodes committed Apr 21, 2024
1 parent 047a851 commit fa50b57
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions app/api/authenticate/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { DeepgramError, createClient } from "@deepgram/sdk";
import { NextResponse } from "next/server";
import { NextResponse, type NextRequest } from "next/server";

export async function GET(request: Request) {
export const revalidate = 0;

export async function GET(request: NextRequest) {
// exit early so we don't request 70000000 keys while in devmode
if (process.env.DEEPGRAM_ENV === "development") {
return NextResponse.json({
Expand Down Expand Up @@ -35,12 +37,20 @@ export async function GET(request: Request) {
comment: "Temporary API key",
scopes: ["usage:write"],
tags: ["next.js"],
time_to_live_in_seconds: 10,
time_to_live_in_seconds: 60,
});

if (newKeyError) {
return NextResponse.json(newKeyError);
}

return NextResponse.json({ ...newKeyResult, url });
const response = NextResponse.json({ ...newKeyResult, url });
response.headers.set("Surrogate-Control", "no-store");
response.headers.set(
"Cache-Control",
"s-maxage=0, no-store, no-cache, must-revalidate, proxy-revalidate"
);
response.headers.set("Expires", "0");

return response;
}

0 comments on commit fa50b57

Please sign in to comment.