More tests
parent
317e05511b
commit
fdb45e3745
|
@ -1,7 +1,7 @@
|
||||||
|
import { PrismaClient } from "@prisma/client";
|
||||||
import { NextMiddleware } from "next-api-middleware";
|
import { NextMiddleware } from "next-api-middleware";
|
||||||
|
|
||||||
import { CONSOLE_URL } from "@calcom/lib/constants";
|
import { CONSOLE_URL } from "@calcom/lib/constants";
|
||||||
import { customPrisma, prisma } from "@calcom/prisma";
|
|
||||||
|
|
||||||
const LOCAL_CONSOLE_URL = process.env.NEXT_PUBLIC_CONSOLE_URL || CONSOLE_URL;
|
const LOCAL_CONSOLE_URL = process.env.NEXT_PUBLIC_CONSOLE_URL || CONSOLE_URL;
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ export const customPrismaClient: NextMiddleware = async (req, res, next) => {
|
||||||
}: { query: { key?: string } } = req;
|
}: { query: { key?: string } } = req;
|
||||||
// If no custom api Id is provided, attach to request the regular cal.com prisma client.
|
// If no custom api Id is provided, attach to request the regular cal.com prisma client.
|
||||||
if (!key) {
|
if (!key) {
|
||||||
req.prisma = prisma;
|
req.prisma = new PrismaClient();
|
||||||
await next();
|
await next();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -26,13 +26,7 @@ export const customPrismaClient: NextMiddleware = async (req, res, next) => {
|
||||||
res.status(400).json({ error: "no databaseUrl set up at your instance yet" });
|
res.status(400).json({ error: "no databaseUrl set up at your instance yet" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
req.prisma = new PrismaClient({ datasources: { db: { url: databaseUrl } } });
|
||||||
/** Attempt to prevent shared connection pools for custom prisma instances */
|
|
||||||
await prisma.$disconnect();
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Couldn't not prisma.$disconnect()");
|
|
||||||
}
|
|
||||||
req.prisma = customPrisma({ datasources: { db: { url: databaseUrl } } });
|
|
||||||
/* @note:
|
/* @note:
|
||||||
In order to skip verifyApiKey for customPrisma requests,
|
In order to skip verifyApiKey for customPrisma requests,
|
||||||
we pass isAdmin true, and userId 0, if we detect them later,
|
we pass isAdmin true, and userId 0, if we detect them later,
|
||||||
|
@ -44,4 +38,6 @@ export const customPrismaClient: NextMiddleware = async (req, res, next) => {
|
||||||
delete req.query.key;
|
delete req.query.key;
|
||||||
await next();
|
await next();
|
||||||
await req.prisma.$disconnect();
|
await req.prisma.$disconnect();
|
||||||
|
// @ts-expect-error testing
|
||||||
|
delete req.prisma;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue