Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

micro

Package Overview
Dependencies
Maintainers
2
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

micro - npm Package Compare versions

Comparing version 6.2.0 to 6.2.1

11

dist/index.js

@@ -43,2 +43,6 @@ // Native

// maps requests to buffered raw bodies so that
// multiple calls to `json` work as expected
const rawBodyMap = new WeakMap()
function json(req, {limit = '1mb'} = {}) {return __async(function*(){

@@ -49,4 +53,9 @@ try {

const encoding = typer.parse(type).parameters.charset
const str = yield getRawBody(req, {limit, length, encoding})
let str = rawBodyMap.get(req)
if (!str) {
str = yield getRawBody(req, {limit, length, encoding})
rawBodyMap.set(req, str)
}
try {

@@ -53,0 +62,0 @@ return JSON.parse(str)

2

package.json
{
"name": "micro",
"version": "6.2.0",
"version": "6.2.1",
"description": "Asynchronous HTTP microservices",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

@@ -100,2 +100,3 @@ ![](https://cldup.com/JDmmHX3uhF.svg)

- Exposes an `async` function that can be run with `await`.
- Can be called multiple times, as it caches the raw request body the first time.
- `limit` is how much data is aggregated before parsing at max. Otherwise, an `Error` is thrown with `statusCode` set to `413` (see [Error Handling](#error-handling)). It can be a `Number` of bytes or [a string](https://www.npmjs.com/package/bytes) like `'1mb'`.

@@ -259,14 +260,15 @@ - If JSON parsing fails, an `Error` is thrown with `statusCode` set to `400` (see [Error Handling](#error-handling))

```js
const micro = require('micro');
const test = require('ava');
const listen = require('./listen');
const send = require('micro').send;
const listen = require('test-listen');
const request = require('request-promise');
test('my endpoint', async t => {
const fn = async function (req, res) {
send(res, 200, { test: 'woot' });
};
const url = await listen(fn);
const service = micro(async function (req, res) {
micro.send(res, 200, { test: 'woot' })
});
const url = await listen(service);
const body = await request(url);
t.same(body.test, 'woot');
t.deepEqual(JSON.parse(body).test, 'woot');
});

@@ -273,0 +275,0 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc