vercel / micro

Asynchronous HTTP microservices
MIT License
10.59k stars 459 forks source link

Add new programmatic usage #399

Closed timneutkens closed 5 years ago

timneutkens commented 5 years ago

Related: https://github.com/zeit/next.js/issues/7297

For serverless functions, @now/node:

const micro = require('micro')

module.exports = micro((req, res) ⇒ {
   return 'Hello World'
})

Current invoking micro() will return a Node.js http.Server which doesn't work well with just req, res as a handler. This also ties into using micro standalone with @now/node. Doing this will also allow us to deprecate micro-dev too in favor of using Next.js / now dev + @now/node

The new programmatic usage works everywhere and really makes Micro a layer on top of the default Node.js request handling.

This solves:

timneutkens commented 5 years ago

Sounds great to me, but out of scope for this PR 👍

zartdinov commented 5 years ago

Looks like need to update README.md.

https://github.com/zeit/micro#programmatic-use https://github.com/zeit/micro#testing

I had some problems with using http.Server

timneutkens commented 5 years ago

Actually no, the readme is correct. It's just not released on stable yet. You can check https://npmjs.com/micro for the stable readme.

zartdinov commented 5 years ago

I understood, thanks!