Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

convert proxy to gerServerSideProps

Steven Tey3d55d49ed39e
diff --git a/lib/api/links.ts b/lib/api/links.ts
index ac8c30106b..13e5b92450 100644
--- a/lib/api/links.ts
+++ b/lib/api/links.ts
@@ -285,12 +285,6 @@ export async function editLink(
.catch(() => {}),
]
: []),
- // if this link has custom OG tags and the key is the same, update the proxy cache
- proxy &&
- !changedKey &&
- (await fetch(
- `https://dub.sh/api/projects/${projectSlug}/domains/${domain}/links/${oldKey}/revalidate?secret=${process.env.REVALIDATE_TOKEN}`,
- )),
]);
if (proxy && image) {
const { secure_url } = effects[0];
diff --git a/pages/_proxy/[domain]/[key].tsx b/pages/_proxy/[domain]/[key].tsx
index bf3e24b398..6b5a838900 100644
--- a/pages/_proxy/[domain]/[key].tsx
+++ b/pages/_proxy/[domain]/[key].tsx
@@ -61,14 +61,7 @@ export default function LinkPage({
);
}
-export function getStaticPaths() {
- return {
- paths: [],
- fallback: "blocking",
- };
-}
-
-export async function getStaticProps(ctx) {
+export async function getServerSideProps(ctx) {
const { domain, key } = ctx.params as { domain: string; key: string };
const link = await prisma.link.findUnique({
where: {
@@ -84,14 +77,12 @@ export async function getStaticProps(ctx) {
if (!url) {
return {
notFound: true,
- revalidate: 1,
};
} else if (!image) {
return {
redirect: {
destination: url,
},
- revalidate: 1,
};
}
@@ -106,6 +97,5 @@ export async function getStaticProps(ctx) {
description,
image,
},
- revalidate: 300,
};
}
diff --git a/pages/api/projects/[slug]/domains/[domain]/links/[key]/revalidate.ts b/pages/api/projects/[slug]/domains/[domain]/links/[key]/revalidate.ts
deleted file mode 100644
index 8e17e21f0e..0000000000
--- a/pages/api/projects/[slug]/domains/[domain]/links/[key]/revalidate.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import type { NextApiRequest, NextApiResponse } from "next";
-
-export default async function handler(
- req: NextApiRequest,
- res: NextApiResponse,
-) {
- if (req.query.secret !== process.env.REVALIDATE_TOKEN) {
- return res.status(401).json({ message: "Invalid token" });
- }
-
- const { domain, key } = req.query as { domain: string; key: string };
-
- try {
- await res.revalidate(`/_proxy/${domain}/${key}`);
- res.status(200).json({
- message: "OK",
- });
- } catch (error) {
- res.status(500).json({
- message: `Failed to revalidate "${`/_proxy/${domain}/${key}`}"`,
- });
- }
-}