The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
stashed domains changes
Steven Tey5b02f712517a
diff --git a/pages/api/cron/domains.ts b/pages/api/cron/domains.tsindex c7994b352b..55b1786da1 100644--- a/pages/api/cron/domains.ts+++ b/pages/api/cron/domains.ts@@ -7,43 +7,59 @@ import {verifyDomain,} from "@/lib/domains";-async function handler(_req: NextApiRequest, res: NextApiResponse) {+export default async function handler(+ _req: NextApiRequest,+ res: NextApiResponse+) {try {const projects = await prisma.project.findMany({- select: {- domain: true,- domainVerified: true,- createdAt: true,+ select: {+ domain: true,+ domainVerified: true,+ createdAt: true,+ },+ orderBy: {+ domainLastChecked: "desc",+ },+ where: {+ domainLastChecked: {+ gte: new Date(new Date().getTime() - 1000 * 60 * 60 * 6), // 7 days ago},- orderBy: {- domainLastChecked: "desc",- },- where: {- domainLastChecked: {- lte: new Date(new Date().getTime() - 1000 * 60 * 60 * 6), // 7 days ago- },- },- take: 500,- })- const statusChanges = await Promise.all(projects.map(async (project) => {+ },+ take: 500,+ });+ const statusChanges = await Promise.all(+ projects.map(async (project) => {const { domain, domainVerified, createdAt } = project;const [domainJson, configJson] = await Promise.all([- getDomainResponse(domain),- getConfigResponse(domain),+ getDomainResponse(domain),+ getConfigResponse(domain),]);let newDomainVerified;- if (domainJson?.error) {- newDomainVerified = false- return {- domain,- status: newDomainVerified,- changed: newDomainVerified !== domainVerified,- };- } else if (!domainJson.verified) {- const verificationJson = await verifyDomain(domain);- if (!configJson.misconfigured) {+ if (!domainJson.verified) {+ const verificationJson = await verifyDomain(domain);+ if (verificationJson && verificationJson.verified) {+ newDomainVerified = false;+ }+ }++ if (!configJson.misconfigured) {+ newDomainVerified = false;+ } else {+ newDomainVerified = true;+ }- }))+ return {+ domain,+ status: newDomainVerified,+ changed: newDomainVerified !== domainVerified,+ invalidOver30Days:+ new Date().getTime() - new Date(createdAt).getTime() >+ 1000 * 60 * 60 * 24 * 30 && newDomainVerified === false,+ };+ })+ );+ res.status(200).json(statusChanges);} catch (error) {res.status(500).json({ error: error.message });}@@ -55,10 +71,10 @@ async function handler(_req: NextApiRequest, res: NextApiResponse) {* To test out the endpoint manually (wihtout using QStash), you can do `export default handler` instead and* hit this endpoint via http://localhost:3000/api/cron*/-export default verifySignature(handler);+// export default verifySignature(handler);-export const config = {- api: {- bodyParser: false,- },-};+// export const config = {+// api: {+// bodyParser: false,+// },+// };