mirror of
https://github.com/honojs/hono.git
synced 2024-12-01 11:51:01 +01:00
bd36ad10fc
* feat(dev): Introduce "dev" helper * feat(dev): Expose "dev" helper * refactor: Use "named function" in some middleware. * feat: `app.showRoutes()` is now deprecated. Use `showRoutes()` in `helper` instead. * refactor: export RouterRoute interface for utility * refactor: remove captureRouteStackTrace, add inspectRoutes `captureRouteStackTrace` will be implemented after some more thought. Instead, I added `inspectRoutes` to get routes as data. * test: add tests for helper/dev/index.ts * fix: run `format:fix` * refactor: use named functions for middleware * chore: denoify * docs: tweaks deprecation warning message * refactor(dev): Simplification of showList options * chore: denoify
17 lines
552 B
TypeScript
17 lines
552 B
TypeScript
import type { MiddlewareHandler } from '../../types.ts'
|
|
|
|
type prettyOptions = {
|
|
space: number
|
|
}
|
|
|
|
export const prettyJSON = (options: prettyOptions = { space: 2 }): MiddlewareHandler => {
|
|
return async function prettyJSON(c, next) {
|
|
const pretty = c.req.query('pretty') || c.req.query('pretty') === '' ? true : false
|
|
await next()
|
|
if (pretty && c.res.headers.get('Content-Type')?.startsWith('application/json')) {
|
|
const obj = await c.res.json()
|
|
c.res = new Response(JSON.stringify(obj, null, options.space), c.res)
|
|
}
|
|
}
|
|
}
|