Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new programmatic usage #399

Merged
merged 1 commit into from May 11, 2019

Conversation

timneutkens
Copy link
Member

@timneutkens timneutkens commented May 11, 2019

Related: vercel/next.js#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:

  • Easier usage (no extra steps needed besides installing and using, like setting up the commands in package.json etc is no longer needed)
  • Easier deployment
  • Scalable by default
  • Serverless by default

Copy link
Member

@javivelasco javivelasco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could be a good idea to add the index.d.ts file with proper types so we can stop using @types/micro and there will be no need to update there either.

@timneutkens
Copy link
Member Author

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

@timneutkens timneutkens removed the request for review from coetry May 11, 2019 14:20
@timneutkens timneutkens merged commit df157df into vercel:master May 11, 2019
@timneutkens timneutkens deleted the add/new-programmatic-api branch May 11, 2019 18:16
@zartdinov
Copy link

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
Copy link
Member Author

timneutkens commented May 14, 2019

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
Copy link

I understood, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants