Initial commit: upload services folder
This commit is contained in:
+1
@@ -0,0 +1 @@
|
||||
../../co-body@6.2.0/node_modules/co-body
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../copy-to@2.0.1/node_modules/copy-to
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
|
||||
4.4.1 / 2023-06-22
|
||||
==================
|
||||
|
||||
**fixes**
|
||||
* [[`5a551b1`](http://github.com/koajs/bodyparser/commit/5a551b1de6f5e2200b8a838207b56ea1198bdb96)] - fix: compatible extra semicolon on content-type header (#153) (fengmk2 <<fengmk2@gmail.com>>)
|
||||
|
||||
4.4.0 / 2023-03-15
|
||||
==================
|
||||
|
||||
**features**
|
||||
* [[`a9a6476`](http://github.com/koajs/bodyparser/commit/a9a647641bb883746c9691e86b8f87739df4e374)] - feat: Support scim json format (#151) (ask me anything :) <<caryyu.tg@gmail.com>>)
|
||||
|
||||
**fixes**
|
||||
* [[`4d931c6`](http://github.com/koajs/bodyparser/commit/4d931c634e9b59a843152f56d68b3ef2e1719675)] - fix: revert html parser, use text directly (dead-horse <<dead_horse@qq.com>>)
|
||||
|
||||
**others**
|
||||
* [[`c02ec0c`](http://github.com/koajs/bodyparser/commit/c02ec0c062f92e1114b4196534669367eae14ccc)] - Update README.md (#149) (sgywzy <<44345776+sgywzy@users.noreply.github.com>>)
|
||||
* [[`85b426f`](http://github.com/koajs/bodyparser/commit/85b426fea3d98481fd4acbafce0857189199426e)] - Recommend @koa/multer for multipart/form-data (#145) (Jim Fisher <<jameshfisher@gmail.com>>)
|
||||
* [[`afecb1a`](http://github.com/koajs/bodyparser/commit/afecb1ab7303ebd36d1a50d6bfe5fc3125759e43)] - Update Repo + Add Html Parser (#134) (imed jaberi <<imed_jebari@hotmail.fr>>)
|
||||
* [[`ecc6ebf`](http://github.com/koajs/bodyparser/commit/ecc6ebfad7179e0009501723e7b2227d25c9603d)] - docs: fix broken npmjs link (#132) (Joel Colucci <<joelcolucci@users.noreply.github.com>>)
|
||||
* [[`336b287`](http://github.com/koajs/bodyparser/commit/336b2879dc7c0e048d79e28bf23d4b8fe2589376)] - Update README.md (haoxin <<haoxinst@gmail.com>>)
|
||||
* [[`e02cb7d`](http://github.com/koajs/bodyparser/commit/e02cb7dd2c798a116ef12c776da30c710697dea5)] - Update README.md (#125) (thaiworldgame <<36978149+thaiworldgame@users.noreply.github.com>>)
|
||||
|
||||
4.3.0 / 2020-03-24
|
||||
==================
|
||||
|
||||
**features**
|
||||
* [[`705673d`](http://github.com/koajs/bodyparser/commit/705673d634818727dbdb25ee999560970bd268a2)] - feat: support xml (#131) (TZ | 天猪 <<atian25@qq.com>>)
|
||||
|
||||
**others**
|
||||
* [[`6fd7e9c`](http://github.com/koajs/bodyparser/commit/6fd7e9c321684adc239d2afb270782c21d0b6231)] - docs: add multipart tips (dead-horse <<dead_horse@qq.com>>)
|
||||
* [[`57c0022`](http://github.com/koajs/bodyparser/commit/57c00225d54b5b5dd1a7526478ad3eae8495222f)] - Fix typo in README.md (#112) (Adrian Pascu <<1521321+adipascu@users.noreply.github.com>>)
|
||||
|
||||
4.2.1 / 2018-05-21
|
||||
==================
|
||||
|
||||
**others**
|
||||
* [[`b270d5d`](http://github.com/koajs/bodyparser/commit/b270d5d138662f41dc63527505ea02dea0c1e7e8)] - deps: upgrade co-body (#104) (Haoliang Gao <<sakura9515@gmail.com>>)
|
||||
* [[`d234345`](http://github.com/koajs/bodyparser/commit/d234345ffa2dadbab2ef0ce970fb8a58059e5f47)] - docs(readme): update opts encode -> encoding (#103) (Matthew Scragg <<scragg@gmail.com>>)
|
||||
* [[`db193f5`](http://github.com/koajs/bodyparser/commit/db193f5d46860393521ad38f90a554968b2ba98a)] - chore:replace indexOf with includes (#90) (coderzzp <<coderzzp@gmail.com>>)
|
||||
|
||||
4.2.0 / 2017-03-21
|
||||
==================
|
||||
|
||||
* feat: ctx.request.rawBody to get raw request body (#70)
|
||||
|
||||
4.1.0 / 2017-03-02
|
||||
==================
|
||||
|
||||
* deps: upgrade co-body@5 (#64)
|
||||
|
||||
4.0.0 / 2017-02-27
|
||||
==================
|
||||
|
||||
* refactor: use async function and support koa@2 (#62)
|
||||
|
||||
2.3.0 / 2016-11-14
|
||||
==================
|
||||
|
||||
* feat: support dynamic disable body parser
|
||||
|
||||
2.2.0 / 2016-05-16
|
||||
==================
|
||||
|
||||
* feat: support enableTypes and text (#44)
|
||||
|
||||
2.1.0 / 2016-05-10
|
||||
==================
|
||||
|
||||
* deps: co-body@4
|
||||
|
||||
2.0.1 / 2015-08-12
|
||||
==================
|
||||
|
||||
* chore: upgrade co-body@3.1.0
|
||||
|
||||
2.0.0 / 2015-05-07
|
||||
==================
|
||||
|
||||
* deps: co-body@2, default to strict mode
|
||||
|
||||
1.6.0 / 2015-05-01
|
||||
==================
|
||||
|
||||
* feat: support custom error handler
|
||||
|
||||
1.5.0 / 2015-04-04
|
||||
==================
|
||||
|
||||
* Use an empty object instead of null, if no body is parsed
|
||||
|
||||
1.4.1 / 2015-03-10
|
||||
==================
|
||||
|
||||
* bump co-body@1.1.0
|
||||
|
||||
1.4.0 / 2015-02-26
|
||||
==================
|
||||
|
||||
* feat: custom json request detect
|
||||
|
||||
1.3.1 / 2015-01-27
|
||||
==================
|
||||
|
||||
* fix: extend
|
||||
|
||||
1.3.0 / 2014-11-27
|
||||
==================
|
||||
|
||||
* support extendTypes
|
||||
* Merge pull request #8 from coderhaoxin/json-patch
|
||||
* add support for json patch
|
||||
|
||||
1.2.0 / 2014-11-07
|
||||
==================
|
||||
|
||||
* add example.js
|
||||
* bump dependencies
|
||||
* Merge pull request #7 from rudijs/develop
|
||||
* Add support for JSON-API
|
||||
|
||||
1.1.0 / 2014-10-28
|
||||
==================
|
||||
|
||||
* Merge pull request #6 from tunnckoCore/master
|
||||
* resolve https://github.com/tunnckoCore/koa-better-body/issues/3#issuecomment-60458238
|
||||
|
||||
1.0.0 / 2014-04-23
|
||||
==================
|
||||
|
||||
* update readme
|
||||
* refactor
|
||||
|
||||
0.1.0 / 2014-03-06
|
||||
==================
|
||||
|
||||
* Merge pull request #2 from fengmk2/remove-co
|
||||
* Remove co deps and improve coverage to 100%
|
||||
|
||||
0.0.2 / 2014-02-26
|
||||
==================
|
||||
|
||||
* Merge pull request #1 from fengmk2/jsonLimit
|
||||
* add jsonLimit options to fix json and form body limit confuse
|
||||
|
||||
0.0.1 / 2014-02-18
|
||||
==================
|
||||
|
||||
* update package name, merge middleware into module.exports
|
||||
* complete readme
|
||||
* complete bodyparser and bodyparser.middleware
|
||||
* Initial commit
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 dead_horse
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
# [**koa-bodyparser**](https://github.com/koajs/bodyparser)
|
||||
|
||||
|
||||
[![NPM version][npm-image]][npm-url]
|
||||
[![build status][travis-image]][travis-url]
|
||||
[![Coveralls][coveralls-image]][coveralls-url]
|
||||
[![David deps][david-image]][david-url]
|
||||
[![node version][node-image]][node-url]
|
||||
|
||||
[npm-image]: https://img.shields.io/npm/v/koa-bodyparser.svg?style=flat-square
|
||||
[npm-url]: https://npmjs.com/package/koa-bodyparser
|
||||
[travis-image]: https://img.shields.io/travis/koajs/bodyparser.svg?style=flat-square
|
||||
[travis-url]: https://travis-ci.org/koajs/bodyparser
|
||||
[coveralls-image]: https://img.shields.io/coveralls/koajs/bodyparser.svg?style=flat-square
|
||||
[coveralls-url]: https://coveralls.io/r/koajs/bodyparser?branch=master
|
||||
[david-image]: https://img.shields.io/david/koajs/bodyparser.svg?style=flat-square
|
||||
[david-url]: https://david-dm.org/koajs/bodyparser
|
||||
[node-image]: https://img.shields.io/badge/node.js-%3E=_8-green.svg?style=flat-square
|
||||
[node-url]: http://nodejs.org/download/
|
||||
|
||||
A body parser for koa, based on [co-body](https://github.com/tj/co-body). support `json`, `form` and `text` type body.
|
||||
|
||||
> Notice: this module doesn't support parsing multipart format data, please use [`@koa/multer`](https://github.com/koajs/multer) to parse multipart format data.
|
||||
|
||||
## Install
|
||||
|
||||
[](https://nodei.co/npm/koa-bodyparser/)
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const Koa = require('koa');
|
||||
const bodyParser = require('koa-bodyparser');
|
||||
|
||||
const app = new Koa();
|
||||
app.use(bodyParser());
|
||||
|
||||
app.use(async ctx => {
|
||||
// the parsed body will store in ctx.request.body
|
||||
// if nothing was parsed, body will be an empty object {}
|
||||
ctx.body = ctx.request.body;
|
||||
});
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
* **enableTypes**: parser will only parse when request type hits enableTypes, support `json/form/text/xml`, default is `['json', 'form']`.
|
||||
* **encoding**: requested encoding. Default is `utf-8` by `co-body`.
|
||||
* **formLimit**: limit of the `urlencoded` body. If the body ends up being larger than this limit, a 413 error code is returned. Default is `56kb`.
|
||||
* **jsonLimit**: limit of the `json` body. Default is `1mb`.
|
||||
* **textLimit**: limit of the `text` body. Default is `1mb`.
|
||||
* **xmlLimit**: limit of the `xml` body. Default is `1mb`.
|
||||
* **strict**: when set to true, JSON parser will only accept arrays and objects. Default is `true`. See [strict mode](https://github.com/cojs/co-body#options) in `co-body`. In strict mode, `ctx.request.body` will always be an object(or array), this avoid lots of type judging. But text body will always return string type.
|
||||
* **detectJSON**: custom json request detect function. Default is `null`.
|
||||
|
||||
```js
|
||||
app.use(bodyParser({
|
||||
detectJSON: function (ctx) {
|
||||
return /\.json$/i.test(ctx.path);
|
||||
}
|
||||
}));
|
||||
```
|
||||
|
||||
* **extendTypes**: support extend types:
|
||||
|
||||
```js
|
||||
app.use(bodyParser({
|
||||
extendTypes: {
|
||||
json: ['application/x-javascript'] // will parse application/x-javascript type body as a JSON string
|
||||
}
|
||||
}));
|
||||
```
|
||||
|
||||
* **onerror**: support custom error handle, if `koa-bodyparser` throw an error, you can customize the response like:
|
||||
|
||||
```js
|
||||
app.use(bodyParser({
|
||||
onerror: function (err, ctx) {
|
||||
ctx.throw(422, 'body parse error');
|
||||
}
|
||||
}));
|
||||
```
|
||||
|
||||
* **disableBodyParser**: you can dynamic disable body parser by set `ctx.disableBodyParser = true`.
|
||||
|
||||
```js
|
||||
app.use(async (ctx, next) => {
|
||||
if (ctx.path === '/disable') ctx.disableBodyParser = true;
|
||||
await next();
|
||||
});
|
||||
app.use(bodyParser());
|
||||
```
|
||||
|
||||
## Raw Body
|
||||
|
||||
You can access raw request body by `ctx.request.rawBody` after `koa-bodyparser` when:
|
||||
|
||||
1. `koa-bodyparser` parsed the request body.
|
||||
2. `ctx.request.rawBody` is not present before `koa-bodyparser`.
|
||||
|
||||
## Koa 1 Support
|
||||
|
||||
To use `koa-bodyparser` with koa@1, please use [bodyparser 2.x](https://github.com/koajs/bodyparser/tree/2.x).
|
||||
|
||||
```bash
|
||||
npm install koa-bodyparser@2 --save
|
||||
```
|
||||
|
||||
#### Licences
|
||||
---
|
||||
[MIT](LICENSE)
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
'use strict';
|
||||
|
||||
const parse = require('co-body');
|
||||
const copy = require('copy-to');
|
||||
const typeis = require('type-is');
|
||||
|
||||
/**
|
||||
* @param [Object] opts
|
||||
* - {String} jsonLimit default '1mb'
|
||||
* - {String} formLimit default '56kb'
|
||||
* - {string} encoding default 'utf-8'
|
||||
* - {Object} extendTypes
|
||||
*/
|
||||
|
||||
module.exports = function(opts) {
|
||||
opts = opts || {};
|
||||
const {detectJSON} = opts;
|
||||
const {onerror} = opts;
|
||||
|
||||
const enableTypes = opts.enableTypes || ['json', 'form'];
|
||||
const enableForm = checkEnable(enableTypes, 'form');
|
||||
const enableJson = checkEnable(enableTypes, 'json');
|
||||
const enableText = checkEnable(enableTypes, 'text');
|
||||
const enableXml = checkEnable(enableTypes, 'xml');
|
||||
|
||||
opts.detectJSON = undefined;
|
||||
opts.onerror = undefined; // eslint-disable-line unicorn/prefer-add-event-listener
|
||||
|
||||
// force co-body return raw body
|
||||
opts.returnRawBody = true;
|
||||
|
||||
// default json types
|
||||
const jsonTypes = [
|
||||
'application/json',
|
||||
'application/json-patch+json',
|
||||
'application/vnd.api+json',
|
||||
'application/csp-report',
|
||||
'application/scim+json'
|
||||
];
|
||||
|
||||
// default form types
|
||||
const formTypes = ['application/x-www-form-urlencoded'];
|
||||
|
||||
// default text types
|
||||
const textTypes = ['text/plain'];
|
||||
|
||||
// default xml types
|
||||
const xmlTypes = ['text/xml', 'application/xml'];
|
||||
|
||||
const jsonOpts = formatOptions(opts, 'json');
|
||||
const formOpts = formatOptions(opts, 'form');
|
||||
const textOpts = formatOptions(opts, 'text');
|
||||
const xmlOpts = formatOptions(opts, 'xml');
|
||||
|
||||
const extendTypes = opts.extendTypes || {};
|
||||
|
||||
extendType(jsonTypes, extendTypes.json);
|
||||
extendType(formTypes, extendTypes.form);
|
||||
extendType(textTypes, extendTypes.text);
|
||||
extendType(xmlTypes, extendTypes.xml);
|
||||
|
||||
// eslint-disable-next-line func-names
|
||||
return async function bodyParser(ctx, next) {
|
||||
if (ctx.request.body !== undefined || ctx.disableBodyParser)
|
||||
return await next(); // eslint-disable-line no-return-await
|
||||
try {
|
||||
const res = await parseBody(ctx);
|
||||
ctx.request.body = 'parsed' in res ? res.parsed : {};
|
||||
if (ctx.request.rawBody === undefined) ctx.request.rawBody = res.raw;
|
||||
} catch (err) {
|
||||
if (onerror) {
|
||||
onerror(err, ctx);
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
await next();
|
||||
};
|
||||
|
||||
async function parseBody(ctx) {
|
||||
if (
|
||||
enableJson &&
|
||||
((detectJSON && detectJSON(ctx)) ||
|
||||
isTypes(ctx.request.get('content-type'), jsonTypes))
|
||||
) {
|
||||
return await parse.json(ctx, jsonOpts); // eslint-disable-line no-return-await
|
||||
}
|
||||
|
||||
if (enableForm && ctx.request.is(formTypes)) {
|
||||
return await parse.form(ctx, formOpts); // eslint-disable-line no-return-await
|
||||
}
|
||||
|
||||
if (enableText && ctx.request.is(textTypes)) {
|
||||
return (await parse.text(ctx, textOpts)) || '';
|
||||
}
|
||||
|
||||
if (enableXml && ctx.request.is(xmlTypes)) {
|
||||
return (await parse.text(ctx, xmlOpts)) || '';
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
function formatOptions(opts, type) {
|
||||
const res = {};
|
||||
copy(opts).to(res);
|
||||
res.limit = opts[type + 'Limit'];
|
||||
return res;
|
||||
}
|
||||
|
||||
function extendType(original, extend) {
|
||||
if (extend) {
|
||||
if (!Array.isArray(extend)) {
|
||||
extend = [extend];
|
||||
}
|
||||
|
||||
extend.forEach(function(extend) {
|
||||
original.push(extend);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function checkEnable(types, type) {
|
||||
return types.includes(type);
|
||||
}
|
||||
|
||||
function isTypes(contentTypeValue, types) {
|
||||
if (typeof contentTypeValue === 'string') {
|
||||
// trim extra semicolon
|
||||
contentTypeValue = contentTypeValue.replace(/;$/, '');
|
||||
}
|
||||
|
||||
return typeis.is(contentTypeValue, types);
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
{
|
||||
"name": "koa-bodyparser",
|
||||
"version": "4.4.1",
|
||||
"description": "a body parser for Koa",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"lint": "xo",
|
||||
"lint:fix": "xo --fix",
|
||||
"test": "mocha --require should test/*.spec.js --exit",
|
||||
"coverage": "nyc npm run test --reporter=lcov",
|
||||
"ci": "npm run lint && npm run coverage"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/koajs/bodyparser.git"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"keywords": [
|
||||
"bodyParser",
|
||||
"json",
|
||||
"urlencoded",
|
||||
"koa",
|
||||
"body"
|
||||
],
|
||||
"author": {
|
||||
"name": "dead_horse",
|
||||
"email": "dead_horse@qq.com",
|
||||
"url": " http://deadhorse.me"
|
||||
},
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"eslint-config-xo-lass": "^1.0.3",
|
||||
"husky": "^4.2.5",
|
||||
"koa": "^2",
|
||||
"mocha": "^10.2.0",
|
||||
"nyc": "^15.0.1",
|
||||
"should": "^13.2.3",
|
||||
"supertest": "^4.0.2",
|
||||
"xo": "0.25.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"co-body": "^6.0.0",
|
||||
"copy-to": "^2.0.1",
|
||||
"type-is": "^1.6.18"
|
||||
},
|
||||
"xo": {
|
||||
"prettier": true,
|
||||
"space": true,
|
||||
"extends": [
|
||||
"xo-lass"
|
||||
],
|
||||
"rules": {
|
||||
"node/no-deprecated-api": "off",
|
||||
"no-unused-vars": "off",
|
||||
"no-prototype-builtins": "off",
|
||||
"prefer-rest-params": "off"
|
||||
},
|
||||
"ignores": [
|
||||
"test/**"
|
||||
]
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8.0.0"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/koajs/body-parser/issues"
|
||||
},
|
||||
"homepage": "https://github.com/koajs/body-parser"
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../type-is@1.6.18/node_modules/type-is
|
||||
Reference in New Issue
Block a user