Skip to content

Commit e467d8c

Browse files
feat: emails (openstatusHQ#93)
1 parent a88be2e commit e467d8c

File tree

26 files changed

+1441
-193
lines changed

26 files changed

+1441
-193
lines changed

apps/web/src/app/action.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Resend } from "resend";
66
import { validateEmailNotDisposable, WaitingList } from "@openstatus/emails";
77

88
import { EmailTemplate } from "@/components/templates/email-template";
9-
import { env } from "@/env.mjs";
9+
import { env } from "@/env";
1010

1111
const redis = Redis.fromEnv();
1212

@@ -50,7 +50,7 @@ const wait = (ms: number): Promise<void> => {
5050
};
5151

5252
// Resend
53-
export const sendWaitingListEmail = async (email:string) => {
53+
export const sendWaitingListEmail = async (email: string) => {
5454
const isValid = await validateEmailNotDisposable(email);
5555
if (!isValid) {
5656
await resend.emails.send({
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { NextResponse } from "next/server";
22

3-
import { cron } from "../_cron";
3+
import { cron, isAuthorizedDomain } from "../_cron";
44

55
export const runtime = "edge";
66
export const preferredRegion = ["auto"];
77
export const dynamic = "force-dynamic";
88

99
export async function GET(req: Request) {
10-
await cron({ periodicity: "10m" });
10+
if (isAuthorizedDomain(req.url)) {
11+
await cron({ periodicity: "10m" });
12+
}
1113
return NextResponse.json({ success: true });
1214
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { NextResponse } from "next/server";
2+
3+
import { cron, isAuthorizedDomain } from "../_cron";
4+
5+
export const runtime = "edge";
6+
export const preferredRegion = ["auto"];
7+
export const dynamic = "force-dynamic";
8+
9+
export async function GET(req: Request) {
10+
if (isAuthorizedDomain(req.url)) {
11+
await cron({ periodicity: "1h" });
12+
}
13+
return NextResponse.json({ success: true });
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { NextResponse } from "next/server";
2+
3+
import { cron, isAuthorizedDomain } from "../_cron";
4+
5+
export const runtime = "edge";
6+
export const preferredRegion = ["auto"];
7+
export const dynamic = "force-dynamic";
8+
9+
export async function GET(req: Request) {
10+
if (isAuthorizedDomain(req.url)) {
11+
await cron({ periodicity: "1m" });
12+
}
13+
return NextResponse.json({ success: true });
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { NextResponse } from "next/server";
2+
3+
import { cron, isAuthorizedDomain } from "../_cron";
4+
5+
export const runtime = "edge";
6+
export const preferredRegion = ["auto"];
7+
export const dynamic = "force-dynamic";
8+
9+
export async function GET(req: Request) {
10+
if (isAuthorizedDomain(req.url)) {
11+
await cron({ periodicity: "30m" });
12+
}
13+
return NextResponse.json({ success: true });
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { NextResponse } from "next/server";
2+
3+
import { cron, isAuthorizedDomain } from "../_cron";
4+
5+
export const runtime = "edge";
6+
export const preferredRegion = ["auto"];
7+
export const dynamic = "force-dynamic";
8+
9+
export async function GET(req: Request) {
10+
if (isAuthorizedDomain(req.url)) {
11+
await cron({ periodicity: "5m" });
12+
}
13+
return NextResponse.json({ success: true });
14+
}

apps/web/src/app/api/checker/cron/_cron.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from "@openstatus/db/src/schema";
1010
import { availableRegions } from "@openstatus/tinybird";
1111

12-
import { env } from "@/env.mjs";
12+
import { env } from "@/env";
1313
import type { payloadSchema } from "../schema";
1414

1515
const periodicityAvailable = selectMonitorSchema.pick({ periodicity: true });
@@ -18,6 +18,11 @@ const DEFAULT_URL = process.env.VERCEL_URL
1818
? `https://${process.env.VERCEL_URL}`
1919
: "http://localhost:3000";
2020

21+
// We can't secure cron endpoint by vercel thus we should make sure they are called by the generated url
22+
export const isAuthorizedDomain = (url: string) => {
23+
return url.includes(DEFAULT_URL);
24+
};
25+
2126
export const cron = async ({
2227
periodicity,
2328
}: z.infer<typeof periodicityAvailable>) => {

apps/web/src/app/api/checker/regions/_checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
Tinybird,
1010
} from "@openstatus/tinybird";
1111

12-
import { env } from "@/env.mjs";
12+
import { env } from "@/env";
1313
import { payloadSchema } from "../schema";
1414

1515
export const monitorSchema = tbIngestPingResponse.pick({

apps/web/src/app/api/ping/route.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { NextResponse } from "next/server";
22

3+
export const dynamic = "force-dynamic";
4+
35
export async function GET() {
46
return NextResponse.json({ ping: "pong" }, { status: 200 });
57
}

apps/web/src/app/api/send/route.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)