{"id":15253543,"url":"https://github.com/feegloo/koa-default-body","last_synced_at":"2026-01-04T13:30:30.874Z","repository":{"id":143882702,"uuid":"329761611","full_name":"feegloo/koa-default-body","owner":"feegloo","description":"Koa middleware: sets ctx.body = '' (response HTTP 200 instead of 404)","archived":false,"fork":false,"pushed_at":"2021-03-22T11:54:37.000Z","size":45,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-03-26T22:21:30.679Z","etag":null,"topics":["koajs","middleware"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/feegloo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-14T23:45:46.000Z","updated_at":"2021-03-22T11:54:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"9da21ab5-a2db-4c56-a2e1-83bbdc0de8bf","html_url":"https://github.com/feegloo/koa-default-body","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feegloo%2Fkoa-default-body","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feegloo%2Fkoa-default-body/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feegloo%2Fkoa-default-body/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feegloo%2Fkoa-default-body/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/feegloo","download_url":"https://codeload.github.com/feegloo/koa-default-body/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244313827,"owners_count":20433011,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["koajs","middleware"],"created_at":"2024-09-29T21:05:24.574Z","updated_at":"2026-01-04T13:30:30.804Z","avatar_url":"https://github.com/feegloo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# koa-default-body\nKoa middleware which sets `ctx.body = ''` to return `HTTP 200`\n\n\u003cbr/\u003e\n\nBy default, if you leave `ctx.body` `undefined`, Koa returns `HTTP 404 Not Found` - this middleware sets `ctx.body = ''` and Koa will return `HTTP 200`\n\nBut if you set `ctx.body` or `ctx.status`, this middleware will use it (instead of setting `ctx.body = ''`)\n\n### example\n\n```\nimport Koa from 'koa'\nimport Router from 'koa-router'\nimport defaultBody from 'koa-default-body'\n\nconst app = new Koa()\nconst router = new Router()\n\nrouter.post('/returns-200-not-404', () =\u003e {})\n\nrouter.get('/return-custom-body-or-status', ctx =\u003e {\n  ctx.body = 'my body my choice'\n  ctx.status = 403\n})\n\napp.use(defaultBody(router))\napp.use(router.routes())\n\napp.listen(3000) // pass your port\n\n```\n\n### purpose\n\nIt's for reducing boilerplate `ctx.body = ''` at the end of route handler (function with ctx), for undefined routes response is still 404 !\n\n  - `ctx.body = ''` is set ONLY for routers registered with `app.use(router.routes())`. When requesting undefined route, like `/foo` - it will still return 404.\n\n### npm package\n\nhttps://www.npmjs.com/package/koa-default-body\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeegloo%2Fkoa-default-body","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffeegloo%2Fkoa-default-body","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeegloo%2Fkoa-default-body/lists"}