1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-07-17 11:35:32 -04:00

convert APIs to edge functions (#1648)

This commit is contained in:
2023-06-25 11:26:29 -04:00
committed by GitHub
parent 62419f1380
commit aa64279dd8
10 changed files with 305 additions and 429 deletions

View File

@@ -1,22 +1,17 @@
import { PrismaClient } from "@prisma/client";
import { IS_DEV_SERVER } from "../config/constants";
import { PrismaClient } from "@prisma/client/edge";
// PrismaClient is attached to the `global` object in development to prevent
// exhausting your database connection limit.
//
// Learn more:
// creating PrismaClient here prevents next.js from starting too many concurrent prisma instances and exhausting the
// number of connection pools available (especially when hot reloading from `next dev`).
// https://pris.ly/d/help/next-js-best-practices
declare global {
// allow global `var` declarations
// eslint-disable-next-line no-var
var prisma: PrismaClient | undefined;
}
const globalForPrisma = globalThis as unknown as {
prisma: PrismaClient | undefined;
};
export const prisma =
global.prisma ||
globalForPrisma.prisma ??
new PrismaClient({
log: ["query"],
});
if (IS_DEV_SERVER) global.prisma = prisma;
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;

View File

@@ -1,38 +0,0 @@
import * as Sentry from "@sentry/node";
import "@sentry/tracing";
import { BUILD_ENV } from "../config/constants";
const IsomorphicSentry = () => {
// https://docs.sentry.io/platforms/node/configuration/options/
Sentry.init({
dsn: process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN || "",
environment: BUILD_ENV,
tracesSampleRate: 1.0,
});
return Sentry;
};
export const logServerError = async (error: unknown) => {
try {
const sentryInstance = IsomorphicSentry();
// log error to sentry
sentryInstance.captureException(error);
// give it 2 seconds to finish sending:
// https://docs.sentry.io/platforms/node/configuration/draining/
await sentryInstance.flush(2000);
} catch (sentryError) {
// cue inception bong
console.error("Encountered an error logging an error... We are doomed.", sentryError);
}
// also log the error normally to the Vercel console; will get picked up by log drain
console.error(error);
// we really don't want to return *any* error from logging an error, so just keep it on the dl
return Promise.resolve();
};
export default IsomorphicSentry;