index.js 531 B

123456789101112131415
  1. // src/middleware/pretty-json/index.ts
  2. var prettyJSON = (options) => {
  3. const targetQuery = options?.query ?? "pretty";
  4. return async function prettyJSON2(c, next) {
  5. const pretty = options?.force || c.req.query(targetQuery) || c.req.query(targetQuery) === "";
  6. await next();
  7. if (pretty && c.res.headers.get("Content-Type")?.startsWith("application/json")) {
  8. const obj = await c.res.json();
  9. c.res = new Response(JSON.stringify(obj, null, options?.space ?? 2), c.res);
  10. }
  11. };
  12. };
  13. export {
  14. prettyJSON
  15. };