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 7.1.0 to 7.2.0

21

bin/micro.js

@@ -28,6 +28,23 @@ #!/usr/bin/env node

args
.option('port', 'Port to listen on', process.env.PORT || 3000)
.option('port', 'Port to listen on', process.env.PORT || 3000, Number)
.option(['H', 'host'], 'Host to listen on', '0.0.0.0')
.option(['s', 'silent'], 'Silent mode')
const flags = args.parse(process.argv)
const flags = args.parse(process.argv, {
minimist: {
alias: {
p: 'port',
H: 'host',
s: 'silent'
},
boolean: [
'silent'
],
string: [
'port',
'host'
]
}
})
let file = args.sub[0]

@@ -34,0 +51,0 @@

37

lib/index.js

@@ -9,3 +9,3 @@ // Packages

module.exports = (file, flags, module = getModule(file)) => {
module.exports = async (file, flags, module = getModule(file)) => {
const server = serve(module)

@@ -16,27 +16,26 @@

detect(port).then(open => {
let inUse = open !== port
const open = await detect(port)
let inUse = open !== port
if (inUse) {
port = open
if (inUse) {
port = open
inUse = {
old: flags.port,
open
}
inUse = {
old: flags.port,
open
}
}
if (host === '0.0.0.0') {
host = null
if (host === '0.0.0.0') {
host = null
}
server.listen(port, host, err => {
if (err) {
console.error('micro:', err.stack)
process.exit(1)
}
server.listen(port, host, async err => {
if (err) {
console.error('micro:', err.stack)
process.exit(1)
}
return await listening(server, inUse)
})
return listening(server, inUse, flags.silent)
})
}
// Packages
const {copy} = require('copy-paste')
const {write: copy} = require('clipboardy')
const ip = require('ip')

@@ -16,3 +16,3 @@ const chalk = require('chalk')

module.exports = async (server, inUse) => {
module.exports = async (server, inUse, silent) => {
const details = server.address()

@@ -29,3 +29,3 @@ const ipAddress = ip.address()

if (!process.env.NOW) {
if (!(silent || process.env.NOW)) {
let message = chalk.green('Micro is running!')

@@ -32,0 +32,0 @@

@@ -10,4 +10,2 @@ // Native

const {resolve} = Promise
const DEV = process.env.NODE_ENV === 'development'

@@ -18,3 +16,4 @@ const TESTING = process.env.NODE_ENV === 'test'

module.exports = exports = serve
module.exports = serve
exports = serve

@@ -26,28 +25,26 @@ exports.send = send

exports.run = (req, res, fn) =>
resolve(fn(req, res))
new Promise(resolve => resolve(fn(req, res)))
.then(val => {
if (val === null) {
if (val === null || val === undefined) {
send(res, 204, null)
return
}
// Return a undefined-null value -> send
if (undefined !== val) {
send(res, res.statusCode || 200, val)
}
send(res, res.statusCode || 200, val)
})
.catch(err => sendError(req, res, err))
// maps requests to buffered raw bodies so that
// Maps requests to buffered raw bodies so that
// multiple calls to `json` work as expected
const rawBodyMap = new WeakMap()
const returnJSON = (resolve, reject, str) => {
const parseJSON = str => {
try {
resolve(JSON.parse(str))
return JSON.parse(str)
} catch (err) {
reject(createError(400, 'Invalid JSON', err))
throw createError(400, 'Invalid JSON', err)
}
}
exports.json = (req, {limit = '1mb'} = {}) => new Promise((resolve, reject) => {
exports.json = (req, {limit = '1mb'} = {}) => Promise.resolve().then(() => {
const type = req.headers['content-type']

@@ -60,11 +57,10 @@ const length = req.headers['content-length']

if (str) {
returnJSON(resolve, reject, str)
return
return parseJSON(str)
}
getRawBody(req, {limit, length, encoding}).then(buf => {
return getRawBody(req, {limit, length, encoding}).then(buf => {
str = buf
rawBodyMap.set(req, str)
returnJSON(resolve, reject, str)
return parseJSON(str)
}).catch(err => {

@@ -108,4 +104,4 @@ if (err.type === 'entity.too.large') {

if (typeof obj === 'object') {
// we stringify before setting the header
if (typeof obj === 'object' || typeof obj === 'number') {
// We stringify before setting the header
// in case `JSON.stringify` throws and a

@@ -130,4 +126,6 @@ // 500 has to be sent instead

function sendError(req, res, {statusCode, status, message, stack}) {
statusCode = statusCode || status
if (statusCode) {
send(res, statusCode || status, DEV ? stack : message)
send(res, statusCode, DEV ? stack : message)
} else {

@@ -134,0 +132,0 @@ send(res, 500, DEV ? stack : 'Internal Server Error')

{
"name": "micro",
"version": "7.1.0",
"version": "7.2.0",
"description": "Asynchronous HTTP microservices",

@@ -13,3 +13,3 @@ "main": "./lib/server.js",

"lint": "xo",
"test": "npm run lint && NODE_ENV=test ava"
"test": "npm run lint && NODE_ENV=test nyc ava"
},

@@ -49,9 +49,11 @@ "xo": {

"ava": "0.18.2",
"husky": "0.13.2",
"request": "2.80.0",
"request-promise": "4.1.1",
"coveralls": "2.12.0",
"husky": "0.13.3-0",
"nyc": "10.1.2",
"request": "2.81.0",
"request-promise": "4.2.0",
"resumer": "0.0.0",
"test-listen": "1.0.1",
"then-sleep": "1.0.1",
"xo": "0.17.1"
"xo": "0.18.0"
},

@@ -64,4 +66,4 @@ "dependencies": {

"chalk": "1.1.3",
"copy-paste": "1.3.0",
"detect-port": "1.1.0",
"clipboardy": "1.0.2",
"detect-port": "1.1.1",
"ip": "1.1.5",

@@ -68,0 +70,0 @@ "is-async-supported": "1.2.0",

@@ -6,2 +6,3 @@ ![](https://raw.githubusercontent.com/zeit/art/31913be3107827adf10e1f491ec61480f63e19af/micro/logo.png)

[![Build Status](https://travis-ci.org/zeit/micro.svg?branch=master)](https://travis-ci.org/zeit/micro)
[![Coverage Status](https://coveralls.io/repos/github/zeit/micro/badge.svg?branch=master)](https://coveralls.io/github/zeit/micro?branch=master)
[![Slack Channel](https://zeit-slackin.now.sh/badge.svg)](https://zeit.chat/)

@@ -8,0 +9,0 @@ [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)

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