All files / src/routes/api log.ts

16.66% Statements 1/6
100% Branches 0/0
0% Functions 0/3
16.66% Lines 1/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27      1x                                              
// Browser log lines; see src/server/platform/client-log.server.ts.
import { createFileRoute } from '@tanstack/react-router'
 
export const Route = createFileRoute('/api/log')({
  server: {
    handlers: {
      // Imported on use: the modules need the Workers runtime, and the route
      // tree is also loaded where there is none (unit tests, the client).
      POST: async ({ request }) => {
        const [{ clientLogResponse }, { getRequestContext }, { consumeLimit }] =
          await Promise.all([
            import('#/server/platform/client-log.server'),
            import('#/server/platform/context.server'),
            import('#/server/platform/limits.server'),
          ])
        const context = getRequestContext()
        return clientLogResponse(request, {
          log: context.log,
          clientIp: context.clientIp(),
          consumeLimit: (key, rule) => consumeLimit(context.db, key, rule),
          userId: async () => (await context.auth.getSession())?.user.id,
        })
      },
    },
  },
})