Comparing version 9.3.4 to 9.3.5-canary.0
// Native | ||
const server = require('http').Server; | ||
const {Stream} = require('stream'); | ||
@@ -8,8 +7,21 @@ | ||
const getRawBody = require('raw-body'); | ||
const {readable} = require('is-stream'); | ||
// based on is-stream https://github.com/sindresorhus/is-stream/blob/c918e3795ea2451b5265f331a00fb6a8aaa27816/license | ||
function isStream(stream) { | ||
return stream !== null && | ||
typeof stream === 'object' && | ||
typeof stream.pipe === 'function'; | ||
} | ||
function readable(stream) { | ||
return isStream(stream) && | ||
stream.readable !== false && | ||
typeof stream._read === 'function' && | ||
typeof stream._readableState === 'object'; | ||
} | ||
const {NODE_ENV} = process.env; | ||
const DEV = NODE_ENV === 'development'; | ||
const serve = fn => server((req, res) => exports.run(req, res, fn)); | ||
const serve = fn => (req, res) => exports.run(req, res, fn); | ||
@@ -16,0 +28,0 @@ module.exports = serve; |
{ | ||
"name": "micro", | ||
"version": "9.3.4", | ||
"version": "9.3.5-canary.0", | ||
"description": "Asynchronous HTTP microservices", | ||
"license": "MIT", | ||
"main": "./lib/index.js", | ||
@@ -10,7 +11,2 @@ "files": [ | ||
], | ||
"scripts": { | ||
"test": "npm run lint && NODE_ENV=test nyc --check-coverage --lines 100 ava", | ||
"lint": "zeit-eslint --ext .jsx,.js .", | ||
"lint-staged": "git diff --diff-filter=ACMRT --cached --name-only '*.js' '*.jsx' | xargs zeit-eslint" | ||
}, | ||
"bin": { | ||
@@ -30,32 +26,8 @@ "micro": "./bin/micro.js" | ||
], | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@zeit/eslint-config-node": "0.2.13", | ||
"@zeit/git-hooks": "0.1.4", | ||
"ava": "0.23.0", | ||
"eslint": "4.19.1", | ||
"husky": "0.14.3", | ||
"nyc": "11.3.0", | ||
"request": "2.83.0", | ||
"request-promise": "4.2.2", | ||
"resumer": "0.0.0", | ||
"rewire": "3.0.2", | ||
"sinon": "4.4.3", | ||
"test-listen": "1.0.2", | ||
"then-sleep": "1.0.1" | ||
}, | ||
"dependencies": { | ||
"arg": "4.1.0", | ||
"content-type": "1.0.4", | ||
"is-stream": "1.1.0", | ||
"raw-body": "2.3.2" | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"@zeit/eslint-config-node" | ||
] | ||
}, | ||
"git": { | ||
"pre-commit": "lint-staged" | ||
} | ||
"gitHead": "3d5738abd9159632f0cc746a320f413291d08a16" | ||
} |
@@ -127,30 +127,2 @@ <img src="https://raw.githubusercontent.com/zeit/art/6451bc300e00312d970527274f316f9b2c07a27e/micro/logo.png" width="50"/> | ||
### Transpilation | ||
The package takes advantage of native support for `async` and `await`, which is available as of **Node.js 8.0.0**! In turn, we suggest either using at least this version both in development and production (if possible), or transpiling the code using [async-to-gen](https://github.com/leebyron/async-to-gen), if you can't use the latest Node.js version. | ||
In order to do that, you firstly need to install it: | ||
```bash | ||
npm install --save async-to-gen | ||
``` | ||
And then add the transpilation command to the `scripts.build` property inside `package.json`: | ||
```json | ||
{ | ||
"scripts": { | ||
"build": "async-to-gen input.js > output.js" | ||
} | ||
} | ||
``` | ||
Once these two steps are done, you can transpile the code by running this command: | ||
```bash | ||
npm run build | ||
``` | ||
That's all it takes to transpile by yourself. But just to be clear: **Only do this if you can't use Node.js 8.0.0**! If you can, `async` and `await` will just work right out of the box. | ||
### Port Based on Environment Variable | ||
@@ -248,9 +220,10 @@ | ||
```js | ||
const http = require('http') | ||
const micro = require('micro') | ||
const sleep = require('then-sleep') | ||
const server = micro(async (req, res) => { | ||
const server = new http.Server(micro(async (req, res) => { | ||
await sleep(500) | ||
return 'Hello world' | ||
}) | ||
})) | ||
@@ -264,3 +237,3 @@ server.listen(3000) | ||
- Use `require('micro')`. | ||
- Returns a [`http.Server`](https://nodejs.org/dist/latest-v6.x/docs/api/http.html#http_class_http_server) that uses the provided `function` as the request handler. | ||
- Returns a function with the `(req, res) => void` signature. That uses the provided `function` as the request handler. | ||
- The supplied function is run with `await`. So it can be `async` | ||
@@ -359,2 +332,3 @@ | ||
```js | ||
const http = require('http') | ||
const micro = require('micro') | ||
@@ -366,7 +340,7 @@ const test = require('ava') | ||
test('my endpoint', async t => { | ||
const service = micro(async (req, res) => { | ||
const service = new http.Server(micro(async (req, res) => { | ||
micro.send(res, 200, { | ||
test: 'woot' | ||
}) | ||
}) | ||
})) | ||
@@ -373,0 +347,0 @@ const url = await listen(service) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
3
0
363
24999
2
370
- Removedis-stream@1.1.0
- Removedis-stream@1.1.0(transitive)