Skip to content

Commit 627d8db

Browse files
committed
use ev.waitUntil instead
1 parent 838dae5 commit 627d8db

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

apps/web/lib/middleware/link.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export async function LinkMiddleware(req: NextRequest, ev: NextFetchEvent) {
9292

9393
if (!linkData) {
9494
if (domain === "buff.ly") {
95-
return await crawlBitly(req);
95+
return await crawlBitly(req, ev);
9696
}
9797

9898
return NextResponse.rewrite(new URL(`/${domain}/notfound`, req.url), {

apps/web/lib/middleware/utils/crawl-bitly.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ import {
88
getUrlFromStringIfValid,
99
linkConstructorSimple,
1010
} from "@dub/utils";
11-
import { waitUntil } from "@vercel/functions";
12-
import { NextRequest, NextResponse } from "next/server";
11+
import { NextFetchEvent, NextRequest, NextResponse } from "next/server";
1312
import { parse } from "./parse";
1413

1514
const BUFFER_WORKSPACE_ID = "cm05wnnpo000711ztj05wwdbu";
1615
const BUFFER_USER_ID = "cm05wnd49000411ztg2xbup0i";
1716
const BUFFER_FOLDER_ID = "fold_1JNQBVZV8P0NA0YGB11W2HHSQ";
1817
const BUFFER_BITLY_API_KEY = process.env.BUFFER_BITLY_API_KEY;
1918

20-
export const crawlBitly = async (req: NextRequest) => {
19+
export const crawlBitly = async (req: NextRequest, ev: NextFetchEvent) => {
2120
const { domain, fullKey: key } = parse(req);
2221

2322
// bitly doesn't support the following characters: ` ~ , . < > ; ‘ : " / \ [ ] ^ { } ( ) = + ! * @ & $ £ ? % # |
@@ -33,7 +32,7 @@ export const crawlBitly = async (req: NextRequest) => {
3332
`[Bitly] Creating link on-demand: ${domain}/${key} (createdAt: ${link.created_at})`,
3433
);
3534
const encodedKey = encodeKeyIfCaseSensitive({ domain, key });
36-
waitUntil(
35+
ev.waitUntil(
3736
prisma.link
3837
.create({
3938
data: {
@@ -50,7 +49,6 @@ export const crawlBitly = async (req: NextRequest) => {
5049
})
5150
.then((data) =>
5251
Promise.allSettled([
53-
// console log outputs
5452
recordLink(data),
5553
prisma.project.update({
5654
where: {

0 commit comments

Comments
 (0)