Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test/*.*.ts
tsup.config.ts
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
node-version: [20.x, 22.x, 24.x]

steps:
- uses: actions/checkout@v2
Expand Down
24 changes: 22 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
.DS_Store*
# OS #
###################
.DS_Store
.idea
Thumbs.db
tmp/
temp/


# Node.js #
###################
node_modules
*.log


# Build #
###################
dist
build

# NYC #
###################
coverage
*.lcov
.nyc_output
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

# Koa Body Parsers
# [**@koa/body-parsers**](https://github.com/koajs/body-parsers)

[![NPM version][npm-image]][npm-url]

Expand All @@ -14,21 +13,22 @@ Includes a `json` and `urlencoded` parsers.
Initialization:

```js
import koaBodyParsers from 'koa-body-parsers'
import Koa from 'koa'
// import withBodyParsers from 'koa-body-parsers'
import { withBodyParsers } from "koa-body-parsers";
import Koa from "koa";

const app = new Koa()
koaBodyParsers(app)
const app = new Koa();
withBodyParsers(app);

// example usage
app.use(async (ctx) => {
const currentUser = UserService.getCurrentUser(ctx)
ctx.assert(currentUser, 401)
const currentUser = UserService.getCurrentUser(ctx);
ctx.assert(currentUser, 401);

ctx.assert(ctx.request.is('json'), 415)
const body = await ctx.request.json('100kb')
ctx.body = body
})
ctx.assert(ctx.request.is("json"), 415);
const body = await ctx.request.json("100kb");
ctx.body = body;
});
```

Because this module is a plugin for the `context`, the API signature is different.
Expand All @@ -41,8 +41,8 @@ Otherwise, create your server like this:
```js
const fn = app.callback();
const server = http.createServer(); // or whatever server you use
server.on('request', fn); // regular requests
server.on('checkContinue', function (req, res) {
server.on("request", fn); // regular requests
server.on("checkContinue", function (req, res) {
// tag requests with `Expect: 100-continue`
req.checkContinue = true;
fn(req, res);
Expand All @@ -57,11 +57,11 @@ but you would still have to call it if you're doing something like:

```js
app.use(async (ctx) => {
if (ctx.request.is('image/*')) {
if (ctx.request.is("image/*")) {
ctx.response.writeContinue();
const buffer = await ctx.request.buffer()
const buffer = await ctx.request.buffer();
}
})
});
```

### const body = await ctx.request.json([limit])
Expand Down
87 changes: 0 additions & 87 deletions index.js

This file was deleted.

Loading