Open History to see the last commit
1import { createMiddleware } from '@tanstack/solid-start'
2β
3export const logMiddleware = createMiddleware({ type: 'function' })
4 .middleware([
5 createMiddleware({ type: 'function' })
6 .client(async (ctx) => {
7 const clientTime = new Date()
8β
9 return await ctx.next({
10 context: {
11 clientTime,
12 },
13 sendContext: {
14 clientTime,
15 },
16 })
17 })
18 .server(async (ctx) => {
19 const serverTime = new Date()
20β
21 return await ctx.next({
22 sendContext: {
23 serverTime,
24 durationToServer:
25 serverTime.getTime() - ctx.context.clientTime.getTime(),
26 },
27 })
28 }),
29 ])
30 .client(async (options) => {
31 const result = await options.next()
32β
33 const now = new Date()
34β
35 console.log('Client Req/Res:', {
36 duration: result.context.clientTime.getTime() - now.getTime(),
37 durationToServer: result.context.durationToServer,
38 durationFromServer: now.getTime() - result.context.serverTime.getTime(),
39 })
40β
41 return result
42 })