File tree Expand file tree Collapse file tree
app/api/github/sync-leaderboard Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { unauthorized } from "next/navigation" ;
12import { NextResponse } from "next/server" ;
3+ import { env } from "~/env" ;
24import syncLeaderboard from "~/server/github/syncLeaderboard" ;
35
4- export async function GET ( ) {
6+ export async function GET ( request : Request ) {
7+ if ( request . headers . get ( "authorization" ) !== `Bearer ${ env . CRON_SECRET } ` ) {
8+ unauthorized ( ) ;
9+ }
10+
511 try {
612 await syncLeaderboard ( ) ;
713 return NextResponse . json ( { success : true } ) ;
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ export const env = createEnv({
1919 . transform ( ( str ) => "https://" + str )
2020 . pipe ( z . url ( ) )
2121 : z . url ( ) . default ( "http://localhost:3000" ) ,
22+ CRON_SECRET : z . string ( ) . min ( 32 ) ,
2223 DEVDOGS_EPOCH : z . coerce . date ( ) . default ( new Date ( 2024 , 7 , 22 ) ) ,
2324 DISCORD_CLIENT_ID : z . string ( ) ,
2425 DISCORD_CLIENT_SECRET : z . string ( ) ,
@@ -68,6 +69,7 @@ export const env = createEnv({
6869 ( process . env . VERCEL_ENV === "production"
6970 ? process . env . VERCEL_PROJECT_PRODUCTION_URL
7071 : process . env . VERCEL_URL ) ,
72+ CRON_SECRET : process . env . CRON_SECRET ,
7173 DEVDOGS_EPOCH : process . env . DEVDOGS_EPOCH ,
7274 GITHUB_CLIENT_ID : process . env . GITHUB_CLIENT_ID ,
7375 GITHUB_CLIENT_SECRET : process . env . GITHUB_CLIENT_SECRET ,
Original file line number Diff line number Diff line change 22 "$schema" : " https://openapi.vercel.sh/vercel.json" ,
33 "git" : {
44 "deploymentEnabled" : false
5+ },
6+ "crons" : [
7+ {
8+ "path" : " /api/github/sync-leaderboard" ,
9+ "schedule" : " 0 0 * * *"
10+ }
11+ ],
12+ "functions" : {
13+ "api/github/sync-leaderboard/route.ts" : {
14+ "maxDuration" : 30
15+ }
516 }
617}
You can’t perform that action at this time.
0 commit comments