Make perfObserver retro-compatible with node v14
parent
74704bb699
commit
7e8dc0f848
|
@ -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) => {
|
||||
|
|
|
@ -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";
|
||||
|
|
Loading…
Reference in New Issue