The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
remove logs and CORS, increased revalidate to 300, used Promise.all, fixed cron
Steven Tey469d5f957c54
diff --git a/pages/api/cron/domains.ts b/pages/api/cron/domains.tsindex 9699f8a73c..cb6277ae7c 100644--- a/pages/api/cron/domains.ts+++ b/pages/api/cron/domains.ts@@ -24,7 +24,7 @@ async function handler(_req: NextApiRequest, res: NextApiResponse) {createdAt: true,},orderBy: {- domainLastChecked: "desc",+ domainLastChecked: "asc",},take: 100,});diff --git a/pages/api/projects/[slug]/domains/[domain]/links/[key]/index.ts b/pages/api/projects/[slug]/domains/[domain]/links/[key]/index.tsindex e44ee469ec..2596aa2db4 100644--- a/pages/api/projects/[slug]/domains/[domain]/links/[key]/index.ts+++ b/pages/api/projects/[slug]/domains/[domain]/links/[key]/index.ts@@ -36,25 +36,20 @@ export default withProjectAuth(invalidate: true,});}- // if there's an image, revalidate proxy page (dub.sh/proxy/[domain]/[key])- await fetch(- `https://dub.sh/api/projects/${slug}/domains/${domain}/links/${oldKey}/revalidate?secret=${process.env.REVALIDATE_TOKEN}`,- {- method: "PUT",- headers: {- "Content-Type": "application/json",- },- }- );}- const response = await editLink(domain, oldKey, {- key,- url,- title,- timestamp,- description,- image,- });+ const [response, _] = await Promise.all([+ editLink(domain, oldKey, {+ key,+ url,+ title,+ timestamp,+ description,+ image,+ }),+ fetch(+ `https://dub.sh/api/projects/${slug}/domains/${domain}/links/${oldKey}/revalidate?secret=${process.env.REVALIDATE_TOKEN}`+ ),+ ]);if (response === null) {return res.status(400).json({ error: "Key already exists" });}diff --git a/pages/api/projects/[slug]/domains/[domain]/links/[key]/revalidate.ts b/pages/api/projects/[slug]/domains/[domain]/links/[key]/revalidate.tsindex 1552e87b34..ec9eeb91eb 100644--- a/pages/api/projects/[slug]/domains/[domain]/links/[key]/revalidate.ts+++ b/pages/api/projects/[slug]/domains/[domain]/links/[key]/revalidate.ts@@ -4,19 +4,12 @@ export default async function handler(req: NextApiRequest,res: NextApiResponse) {- console.log("first received request", req.headers.host);-if (req.query.secret !== process.env.REVALIDATE_TOKEN) {return res.status(401).json({ message: "Invalid token" });}- console.log("valid secret", req.headers.host);const { domain, key } = req.query as { domain: string; key: string };- res.setHeader("Access-Control-Allow-Origin", "*");- res.setHeader("Access-Control-Allow-Methods", "PUT");- console.log("passed CORS", domain, key, req.headers.host);-try {await res.revalidate(`/proxy/${domain}/${key}`);res.status(200).json({diff --git a/pages/proxy/[domain]/[key].tsx b/pages/proxy/[domain]/[key].tsxindex 237701e827..00f855ed84 100644--- a/pages/proxy/[domain]/[key].tsx+++ b/pages/proxy/[domain]/[key].tsx@@ -88,6 +88,6 @@ export async function getStaticProps(ctx) {image,logo: project?.logo,},- revalidate: 60,+ revalidate: 300,};}