Skip to content

Commit

Permalink
bring back default http server wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
walaszczykm committed Jul 29, 2022
1 parent e69ce5b commit 7e4d46e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
17 changes: 7 additions & 10 deletions packages/micro/README.md
Expand Up @@ -214,18 +214,15 @@ module.exports = async (req, res) => {
You can use Micro programmatically by requiring Micro directly:

```js
const http = require('http');
const micro = require('micro');
const sleep = require('then-sleep');
const micro = require('micro')
const sleep = require('then-sleep')

const server = new http.Server(
micro(async (req, res) => {
await sleep(500);
return 'Hello world';
})
);
const server = micro(async (req, res) => {
await sleep(500)
return 'Hello world'
})

server.listen(3000);
server.listen(3000)
```

##### micro(fn)
Expand Down
3 changes: 2 additions & 1 deletion packages/micro/lib/index.js
@@ -1,4 +1,5 @@
// Native
const server = require('http').Server;
const {Stream} = require('stream');

// Packages
Expand All @@ -22,7 +23,7 @@ function readable(stream) {
const {NODE_ENV} = process.env;
const DEV = NODE_ENV === 'development';

const serve = fn => (req, res) => exports.run(req, res, fn);
const serve = fn => server((req, res) => exports.run(req, res, fn));

module.exports = serve;
exports = serve;
Expand Down

0 comments on commit 7e4d46e

Please sign in to comment.