@pyreon/zero 0.24.4 → 0.24.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +10 -39
- package/src/actions.ts +0 -196
- package/src/adapters/bun.ts +0 -114
- package/src/adapters/cloudflare.ts +0 -166
- package/src/adapters/index.ts +0 -61
- package/src/adapters/netlify.ts +0 -154
- package/src/adapters/node.ts +0 -163
- package/src/adapters/static.ts +0 -42
- package/src/adapters/validate.ts +0 -23
- package/src/adapters/vercel.ts +0 -182
- package/src/adapters/warn-missing-env.ts +0 -49
- package/src/ai.ts +0 -623
- package/src/api-routes.ts +0 -219
- package/src/app.ts +0 -92
- package/src/cache.ts +0 -136
- package/src/client.ts +0 -143
- package/src/compression.ts +0 -116
- package/src/config.ts +0 -35
- package/src/cors.ts +0 -94
- package/src/csp.ts +0 -226
- package/src/entry-server.ts +0 -224
- package/src/env.ts +0 -344
- package/src/error-overlay.ts +0 -118
- package/src/favicon.ts +0 -841
- package/src/font.ts +0 -511
- package/src/fs-router.ts +0 -1519
- package/src/i18n-routing.ts +0 -533
- package/src/icon.tsx +0 -182
- package/src/icons-plugin.ts +0 -296
- package/src/image-plugin.ts +0 -751
- package/src/image-types.ts +0 -60
- package/src/image.tsx +0 -340
- package/src/index.ts +0 -92
- package/src/isr.ts +0 -394
- package/src/link.tsx +0 -304
- package/src/logger.ts +0 -144
- package/src/manifest.ts +0 -787
- package/src/meta.tsx +0 -354
- package/src/middleware.ts +0 -65
- package/src/not-found.ts +0 -44
- package/src/og-image.ts +0 -378
- package/src/rate-limit.ts +0 -140
- package/src/script.tsx +0 -260
- package/src/seo.ts +0 -617
- package/src/server.ts +0 -89
- package/src/sharp.d.ts +0 -22
- package/src/ssg-plugin.ts +0 -1582
- package/src/testing.ts +0 -146
- package/src/theme.tsx +0 -257
- package/src/types.ts +0 -624
- package/src/utils/use-intersection-observer.ts +0 -36
- package/src/utils/with-headers.ts +0 -13
- package/src/vercel-revalidate-handler.ts +0 -204
- package/src/vite-plugin.ts +0 -848
package/src/logger.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Request logging middleware.
|
|
3
|
-
*
|
|
4
|
-
* Logs HTTP requests with method, path, status, and duration.
|
|
5
|
-
* Supports custom formatters and log levels.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* import { loggerMiddleware } from "@pyreon/zero"
|
|
10
|
-
*
|
|
11
|
-
* export default defineConfig({
|
|
12
|
-
* middleware: [loggerMiddleware()],
|
|
13
|
-
* })
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
import type { Middleware, MiddlewareContext } from '@pyreon/server'
|
|
17
|
-
|
|
18
|
-
export interface LoggerConfig {
|
|
19
|
-
/**
|
|
20
|
-
* Log level — controls which requests are logged.
|
|
21
|
-
* - "all": log every request
|
|
22
|
-
* - "none": disable logging
|
|
23
|
-
* Default: "all"
|
|
24
|
-
*/
|
|
25
|
-
level?: 'all' | 'none'
|
|
26
|
-
/**
|
|
27
|
-
* Custom log formatter. Receives request details and returns
|
|
28
|
-
* the string to log (or null to skip).
|
|
29
|
-
*/
|
|
30
|
-
format?: (entry: LogEntry) => string | null
|
|
31
|
-
/**
|
|
32
|
-
* Skip logging for these path prefixes.
|
|
33
|
-
* Default: ["/__", "/@", "/node_modules"]
|
|
34
|
-
*/
|
|
35
|
-
skip?: string[]
|
|
36
|
-
/**
|
|
37
|
-
* Enable colorized output (ANSI codes).
|
|
38
|
-
* Default: true in development, false in production.
|
|
39
|
-
*/
|
|
40
|
-
colors?: boolean
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface LogEntry {
|
|
44
|
-
method: string
|
|
45
|
-
path: string
|
|
46
|
-
duration: number
|
|
47
|
-
timestamp: Date
|
|
48
|
-
userAgent?: string | undefined
|
|
49
|
-
ip?: string | undefined
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const COLORS = {
|
|
53
|
-
reset: '\x1b[0m',
|
|
54
|
-
dim: '\x1b[2m',
|
|
55
|
-
green: '\x1b[32m',
|
|
56
|
-
yellow: '\x1b[33m',
|
|
57
|
-
red: '\x1b[31m',
|
|
58
|
-
cyan: '\x1b[36m',
|
|
59
|
-
magenta: '\x1b[35m',
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function methodColor(method: string, colors: boolean): string {
|
|
63
|
-
if (!colors) return method.padEnd(7)
|
|
64
|
-
const padded = method.padEnd(7)
|
|
65
|
-
switch (method) {
|
|
66
|
-
case 'GET': return `${COLORS.green}${padded}${COLORS.reset}`
|
|
67
|
-
case 'POST': return `${COLORS.cyan}${padded}${COLORS.reset}`
|
|
68
|
-
case 'PUT': return `${COLORS.yellow}${padded}${COLORS.reset}`
|
|
69
|
-
case 'PATCH': return `${COLORS.yellow}${padded}${COLORS.reset}`
|
|
70
|
-
case 'DELETE': return `${COLORS.red}${padded}${COLORS.reset}`
|
|
71
|
-
default: return `${COLORS.magenta}${padded}${COLORS.reset}`
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function defaultFormat(entry: LogEntry, colors: boolean): string {
|
|
76
|
-
const dur = entry.duration < 1
|
|
77
|
-
? '<1ms'
|
|
78
|
-
: entry.duration < 1000
|
|
79
|
-
? `${Math.round(entry.duration)}ms`
|
|
80
|
-
: `${(entry.duration / 1000).toFixed(2)}s`
|
|
81
|
-
|
|
82
|
-
const dim = colors ? COLORS.dim : ''
|
|
83
|
-
const reset = colors ? COLORS.reset : ''
|
|
84
|
-
|
|
85
|
-
return ` ${methodColor(entry.method, colors)} ${entry.path} ${dim}${dur}${reset}`
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Request logging middleware.
|
|
90
|
-
*
|
|
91
|
-
* Logs incoming requests with method, path, and duration.
|
|
92
|
-
* Runs in middleware phase — logs timing from middleware start to
|
|
93
|
-
* microtask completion (approximate request duration).
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* ```ts
|
|
97
|
-
* // Basic usage
|
|
98
|
-
* loggerMiddleware()
|
|
99
|
-
*
|
|
100
|
-
* // Custom format
|
|
101
|
-
* loggerMiddleware({
|
|
102
|
-
* format: (e) => `${e.method} ${e.path} (${e.duration}ms)`,
|
|
103
|
-
* })
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
|
-
export function loggerMiddleware(config?: LoggerConfig): Middleware {
|
|
107
|
-
const level = config?.level ?? 'all'
|
|
108
|
-
if (level === 'none') return () => {}
|
|
109
|
-
|
|
110
|
-
const skip = config?.skip ?? ['/__', '/@', '/node_modules']
|
|
111
|
-
const isDev = typeof process !== 'undefined' && process.env.NODE_ENV !== 'production'
|
|
112
|
-
const colors = config?.colors ?? isDev
|
|
113
|
-
|
|
114
|
-
return (ctx: MiddlewareContext) => {
|
|
115
|
-
// Skip internal paths
|
|
116
|
-
if (skip.some((p) => ctx.path.startsWith(p))) return
|
|
117
|
-
|
|
118
|
-
const start = performance.now()
|
|
119
|
-
|
|
120
|
-
const entry: LogEntry = {
|
|
121
|
-
method: ctx.req.method ?? 'GET',
|
|
122
|
-
path: ctx.path,
|
|
123
|
-
duration: 0,
|
|
124
|
-
timestamp: new Date(),
|
|
125
|
-
userAgent: ctx.req.headers.get('user-agent') ?? undefined,
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// Use queueMicrotask to log after the middleware chain completes
|
|
129
|
-
queueMicrotask(() => {
|
|
130
|
-
entry.duration = performance.now() - start
|
|
131
|
-
|
|
132
|
-
if (config?.format) {
|
|
133
|
-
const line = config.format(entry)
|
|
134
|
-
if (line) {
|
|
135
|
-
// oxlint-disable-next-line no-console
|
|
136
|
-
console.log(line)
|
|
137
|
-
}
|
|
138
|
-
} else {
|
|
139
|
-
// oxlint-disable-next-line no-console
|
|
140
|
-
console.log(defaultFormat(entry, colors))
|
|
141
|
-
}
|
|
142
|
-
})
|
|
143
|
-
}
|
|
144
|
-
}
|