Compare commits

...

2 Commits

Author SHA1 Message Date
e8c5eb9d85 0.0.2 2026-01-30 21:55:02 -08:00
1576d92efc logging: false 2026-01-30 21:54:44 -08:00
2 changed files with 14 additions and 11 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@because/hype", "name": "@because/hype",
"version": "0.0.1", "version": "0.0.2",
"module": "src/index.tsx", "module": "src/index.tsx",
"type": "module", "type": "module",
"exports": { "exports": {

View File

@ -24,6 +24,7 @@ export type HypeProps = {
reset?: boolean reset?: boolean
prettyHTML?: boolean prettyHTML?: boolean
layout?: boolean layout?: boolean
logging?: boolean
} }
type InternalProps = HypeProps & { _isRouter?: boolean } type InternalProps = HypeProps & { _isRouter?: boolean }
@ -89,16 +90,18 @@ export class Hype<
this.use('/css/*', serveStatic({ root: './src' })) this.use('/css/*', serveStatic({ root: './src' }))
// console logging // console logging
this.use('*', async (c, next) => { if (this.props.logging !== false) {
if (!SHOW_HTTP_LOG) return await next() this.use('*', async (c, next) => {
if (!SHOW_HTTP_LOG) return await next()
const start = Date.now() const start = Date.now()
await next() await next()
const end = Date.now() const end = Date.now()
const fn = c.res.status < 400 ? color.green : c.res.status < 500 ? color.yellow : color.red const fn = c.res.status < 400 ? color.green : c.res.status < 500 ? color.yellow : color.red
const method = c.req.method === 'GET' ? color.cyan(c.req.method) : color.magenta(c.req.method) const method = c.req.method === 'GET' ? color.cyan(c.req.method) : color.magenta(c.req.method)
console.log(fn(`${c.res.status}`), `${color.bold(method)} ${c.req.url} (${end - start}ms)`) console.log(fn(`${c.res.status}`), `${color.bold(method)} ${c.req.url} (${end - start}ms)`)
}) })
}
// exception handler // exception handler
this.onError((err, c) => { this.onError((err, c) => {