Make perfObserver retro-compatible with node v14

pull/3052/head
zomars 2022-06-14 09:32:37 -06:00
parent 74704bb699
commit 7e8dc0f848
2 changed files with 5 additions and 5 deletions

View File

@ -1,13 +1,10 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { performance } from "perf_hooks";
import { perfObserver } from ".";
import { getServerErrorFromUnkown } from "./getServerErrorFromUnkown";
import { performance } from "./perfObserver";
type Handle<T> = (req: NextApiRequest, res: NextApiResponse) => Promise<T>;
perfObserver.observe({ type: "measure" });
/** Allows us to get type inference from API handler responses */
function defaultResponder<T>(f: Handle<T>) {
return async (req: NextApiRequest, res: NextApiResponse) => {

View File

@ -7,10 +7,11 @@ declare global {
export const perfObserver =
globalThis.perfObserver ||
new PerformanceObserver((items) => {
new PerformanceObserver((items, observer) => {
items.getEntries().forEach((entry) => {
console.log(entry); // fake call to our custom logging solution
});
observer.observe({ entryTypes: ["measure"] });
});
if (process.env.NODE_ENV !== "production") {
@ -18,3 +19,5 @@ if (process.env.NODE_ENV !== "production") {
}
export default perfObserver;
export { performance } from "perf_hooks";