Skip to content

Commit

Permalink
vercel#369 update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
alisabzevari committed Jan 28, 2019
1 parent 1445af1 commit f4017d6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/socket.io-chat-app/index.js
@@ -1,4 +1,4 @@
const { micro } = require('micro');
const micro = require('micro');
const fs = require('fs');
const path = require('path');

Expand Down
3 changes: 1 addition & 2 deletions examples/with-graphql-request/README.md
Expand Up @@ -18,8 +18,7 @@ $ yarn run start # (or `$ npm run start`)

Test it:
```bash
curl --request GET \
--url http://localhost:3000/
curl http://localhost:3000/

# Expected curl result:
# {"releaseDate":"2010-08-28T20:00:00.000Z","actors":[{"name":"Leonardo DiCaprio"},{"name":"Ellen Page"},{"name":"Tom Hardy"},{"name":"Joseph Gordon-Levitt"},{"name":"Marion Cotillard"}]}
Expand Down
2 changes: 1 addition & 1 deletion examples/with-https/README.md
Expand Up @@ -18,7 +18,7 @@ npm run start

Test it:
```bash
curl -k --request GET --url https://localhost:3443/
curl -k https://localhost:3443/

# Expected curl result:
# {"encrypted":true}
Expand Down
11 changes: 6 additions & 5 deletions examples/with-https/index.js
@@ -1,17 +1,18 @@
const https = require('https');
const { listener, res } = require('micro');
const { run, send } = require('micro');

const { key, cert, passphrase } = require('openssl-self-signed-certificate');

const PORT = process.env.PORT || 3443;

const options = { key, cert, passphrase };

const microHttps = fn => https.createServer(options, listener(fn));
const microHttps = fn =>
https.createServer(options, (req, res) => run(req, res, fn));

const handler = req => res({ encrypted: req.client.encrypted }, 200);

const server = microHttps(handler);
const server = microHttps(async (req, res) => {
send(res, 200, { encrypted: req.client.encrypted });
});

server.listen(PORT);
console.log(`Listening on https://localhost:${PORT}`);
21 changes: 18 additions & 3 deletions src/index.ts
Expand Up @@ -2,11 +2,9 @@ import { Server } from "http";

import { HttpHandler, run, send, serve, sendError } from "./micro";
import { buffer, json, text } from "./helpers";
export { res, Body, HttpRequest, HttpResponse } from "./http-message";
import { res, Body, HttpRequest, HttpResponse } from "./http-message";
import { createError } from "./error";

export { HttpHandler };

export interface Micro {
(fn: HttpHandler): Server;
send: typeof send;
Expand All @@ -28,3 +26,20 @@ micro.text = text;
micro.json = json;

export default micro as Micro;
export {
HttpHandler,
run,
send,
serve,
sendError,
buffer,
json,
text,
res,
Body,
HttpRequest,
HttpResponse,
createError
}
module.exports = serve;
exports = serve;

0 comments on commit f4017d6

Please sign in to comment.