1
- import { NextRequest , NextResponse } from "next/server" ;
2
-
3
- export const config = {
4
- runtime : "edge" ,
5
- regions : [ "iad1" ] , // specify a single region
6
- } ;
7
-
8
- // This defines a schedule for running once a week (Sunday at 00:00 UTC)
9
- export const dynamic = "force-dynamic" ;
10
- export const revalidate = 0 ;
11
-
12
- // Set the cron schedule to run monthly (1st day of each month at midnight)
13
- export const maxDuration = 300 ; // 5 minute maximum duration
14
- export const schedule = { cron : "0 0 1 * *" } ; // Monthly at midnight on the 1st day
15
-
16
- export async function GET ( request : NextRequest ) {
1
+ import { NextResponse } from "next/server" ;
2
+
3
+ /**
4
+ * This route is called by Vercel Cron Jobs
5
+ * Cron configuration is set in vercel.json at the project root
6
+ * Schedule: Monthly at midnight on the 1st day of each month
7
+ */
8
+ export async function GET ( ) {
17
9
try {
18
10
const secretKey = process . env . SYNC_SECRET_KEY || "your-default-secret-key" ;
19
11
20
12
// Call our sync API
21
13
const syncResponse = await fetch (
22
14
`${
23
- process . env . NEXT_PUBLIC_BASE_URL || request . nextUrl . origin
15
+ process . env . NEXT_PUBLIC_BASE_URL || "https://your-app-url.com"
24
16
} /api/syncAllProfiles?secretKey=${ secretKey } `,
25
17
{ method : "GET" }
26
18
) ;
@@ -30,19 +22,19 @@ export async function GET(request: NextRequest) {
30
22
if ( ! result . success ) {
31
23
console . error ( "Sync failed:" , result ) ;
32
24
return NextResponse . json (
33
- { message : "Weekly sync failed" , error : result } ,
25
+ { message : "Monthly sync failed" , error : result } ,
34
26
{ status : 500 }
35
27
) ;
36
28
}
37
29
38
30
return NextResponse . json ( {
39
- message : "Weekly sync completed successfully" ,
31
+ message : "Monthly sync completed successfully" ,
40
32
result,
41
33
} ) ;
42
34
} catch ( error ) {
43
35
console . error ( "Error during scheduled sync:" , error ) ;
44
36
return NextResponse . json (
45
- { message : "Error during weekly sync" , error } ,
37
+ { message : "Error during monthly sync" , error } ,
46
38
{ status : 500 }
47
39
) ;
48
40
}
0 commit comments