Hooks: Log requests
This commit is contained in:
@ -8,6 +8,8 @@ import PocketBase from "pocketbase";
|
|||||||
// most recent authentication data.
|
// most recent authentication data.
|
||||||
// The authenticated PocketBase client will be available in all *.server.ts files.
|
// The authenticated PocketBase client will be available in all *.server.ts files.
|
||||||
export const handle: Handle = async ({ event, resolve }) => {
|
export const handle: Handle = async ({ event, resolve }) => {
|
||||||
|
const requestStartTime: number = Date.now();
|
||||||
|
|
||||||
event.locals.pb = new PocketBase("http://192.168.86.50:8090");
|
event.locals.pb = new PocketBase("http://192.168.86.50:8090");
|
||||||
|
|
||||||
// Load the most recent authentication data from a cookie (is updated below)
|
// Load the most recent authentication data from a cookie (is updated below)
|
||||||
@ -45,6 +47,15 @@ export const handle: Handle = async ({ event, resolve }) => {
|
|||||||
// Resolve the request. This is what happens by default.
|
// Resolve the request. This is what happens by default.
|
||||||
const response = await resolve(event);
|
const response = await resolve(event);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
"=====\n",
|
||||||
|
`Request Date: ${new Date(requestStartTime).toISOString()}\n`,
|
||||||
|
`Method: ${event.request.method}\n`,
|
||||||
|
`Path: ${event.url.pathname}\n`,
|
||||||
|
`Duration: ${Date.now() - requestStartTime}ms\n`,
|
||||||
|
`Status: ${response.status}`,
|
||||||
|
);
|
||||||
|
|
||||||
// Store the current authentication data to a cookie, so it can be loaded above.
|
// Store the current authentication data to a cookie, so it can be loaded above.
|
||||||
response.headers.set("set-cookie", event.locals.pb.authStore.exportToCookie({ secure: false }));
|
response.headers.set("set-cookie", event.locals.pb.authStore.exportToCookie({ secure: false }));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user