Add debug page

This commit is contained in:
Fergal Moran
2024-01-14 21:26:53 +00:00
parent 4862996910
commit b408004039
4 changed files with 64 additions and 10 deletions

View File

@@ -0,0 +1,15 @@
import PrintEnv from "@/components/widgets/print-env";
import { authOptions } from "@/server/auth";
import { getServerSession } from "next-auth";
import { headers } from "next/headers";
const DebugPage = async () => {
const session = await getServerSession(authOptions);
const request = headers();
return (
<div className="p-6">
<PrintEnv session={null} request={request} />
</div>
);
};
export default DebugPage;

View File

@@ -1,10 +0,0 @@
import QRCode from 'react-qr-code';
const DebugPage = () => {
return (
<div>
<QRCode value="7506" />
</div>
);
};
export default DebugPage;

View File

@@ -0,0 +1,19 @@
import { type Session } from "next-auth";
import { type ReadonlyHeaders } from "next/dist/server/web/spec-extension/adapters/headers";
import React from "react";
import { env } from "@/env";
type PrintEnvProps = {
session: Session | null;
request: ReadonlyHeaders;
};
const PrintEnv: React.FC<PrintEnvProps> = ({ session, request }) => {
return (
<div className="flex flex-col space-x-4">
<div>{JSON.stringify(session, null, 2)}</div>
<div>{JSON.stringify(request, null, 2)}</div>
<div>{JSON.stringify(env, null, 2)}</div>
</div>
);
};
export default PrintEnv;

30
src/lib/helpers/debug.ts Normal file
View File

@@ -0,0 +1,30 @@
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-call */
export function syntaxHighlight(json) {
if (typeof json != "string") {
json = JSON.stringify(json, undefined, 2);
}
json = json
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;");
return json.replace(
/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,
function (match) {
var cls = "number";
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = "key";
} else {
cls = "string";
}
} else if (/true|false/.test(match)) {
cls = "boolean";
} else if (/null/.test(match)) {
cls = "null";
}
return '<span class="' + cls + '">' + match + "</span>";
},
);
}