forked from accensa/accensa-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch_route.js
More file actions
55 lines (51 loc) · 2.58 KB
/
Copy pathpatch_route.js
File metadata and controls
55 lines (51 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import fs from 'fs';
const path = 'apps/web/src/app/api/sync/route.ts';
let content = fs.readFileSync(path, 'utf8');
const conflict = `<<<<<<< HEAD
* CRON_SECRET, checked with a constant-time compare in isAuthorizedCronRequest
* (@/lib/cron-auth) - both senders pass it as a bearer token - so the
* endpoint cannot be driven by arbitrary callers. An unset CRON_SECRET fails
* closed: middleware.ts already denies this path before it reaches here, and
* this check denies it too, since no caller should ever run a sync against a
* deployment with no secret configured. No cooldown: a scheduled run is
* already rate limited by its schedule.
*/
export async function GET(request: Request) {
if (!isAuthorizedCronRequest(request.headers.get('authorization'))) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
=======
* CRON_SECRET when set - both senders pass it as a bearer token - so the
* endpoint cannot be driven by arbitrary callers. No cooldown: a scheduled run
* is already rate limited by its schedule.
*
* Sweeps every configured merchant in turn, each with its own cursor - a
* merchant with no activity still has its cursor advanced (see runSync),
* which is precisely the fix for the outage that motivated this workflow's
* checks in the first place.
*/
export async function GET(request: Request) {
const secret = process.env.CRON_SECRET;
if (secret && request.headers.get('authorization') !== \`Bearer \${secret}\`) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
>>>>>>> origin/main`;
const replacement = ` * CRON_SECRET, checked with a constant-time compare in isAuthorizedCronRequest
* (@/lib/cron-auth) - both senders pass it as a bearer token - so the
* endpoint cannot be driven by arbitrary callers. An unset CRON_SECRET fails
* closed: middleware.ts already denies this path before it reaches here, and
* this check denies it too, since no caller should ever run a sync against a
* deployment with no secret configured. No cooldown: a scheduled run is
* already rate limited by its schedule.
*
* Sweeps every configured merchant in turn, each with its own cursor - a
* merchant with no activity still has its cursor advanced (see runSync),
* which is precisely the fix for the outage that motivated this workflow's
* checks in the first place.
*/
export async function GET(request: Request) {
if (!isAuthorizedCronRequest(request.headers.get('authorization'))) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}`;
content = content.replace(conflict, replacement);
fs.writeFileSync(path, content);