diff --git a/api/.env.local.example b/api/.env.local.example new file mode 100644 index 0000000..901cfb9 --- /dev/null +++ b/api/.env.local.example @@ -0,0 +1,2 @@ +# Required for the random-color-theme API, needs editor role or higher +SANITY_API_WRITE_TOKEN= \ No newline at end of file diff --git a/api/api/random-color-theme.ts b/api/api/random-color-theme.ts index 5fd3eea..813b50f 100644 --- a/api/api/random-color-theme.ts +++ b/api/api/random-color-theme.ts @@ -70,7 +70,11 @@ export default async function handler(request: Request) { }) const _id = 'theme' const patch = client.patch(_id).set(generateThemeColors()) - await client.transaction().createIfNotExists({_id, _type: _id}).patch(patch).commit() + await Promise.allSettled([ + client.transaction().createIfNotExists({_id, _type: _id}).patch(patch).commit(), + // Wait 3 seconds to stagger requests a little bit + new Promise((resolve) => setTimeout(resolve, 3_000)), + ]) return new Response(JSON.stringify({patch}), {status: 200, headers}) } catch (err) {