Skip to content

Commit

Permalink
vercel#369 Update examples to work with new api
Browse files Browse the repository at this point in the history
  • Loading branch information
alisabzevari committed Jan 25, 2019
1 parent 0c3f3ca commit 68411e5
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 12 deletions.
8 changes: 8 additions & 0 deletions examples/external-api-call/README.md
Expand Up @@ -17,6 +17,14 @@ npm install
npm run start
```

Test it:
```bash
curl http://localhost:3000

# Expected result:
# {"userId":1,"id":1,"title":"delectus aut autem","completed":false}
```

Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))

```bash
Expand Down
2 changes: 1 addition & 1 deletion examples/external-api-call/index.js
@@ -1,7 +1,7 @@
const fetch = require('node-fetch');

module.exports = async () => {
const response = await fetch('https://api.example.com');
const response = await fetch('https://jsonplaceholder.typicode.com/todos/1');
const json = await response.json();

return json;
Expand Down
16 changes: 16 additions & 0 deletions examples/json-body-parsing/README.md
Expand Up @@ -17,6 +17,22 @@ npm install
npm run start
```

Test it:
```bash
curl --request GET \
--url http://localhost:3000/ \
--data '{"userId":1,"id":1,"title":"delectus aut autem","completed":false}'

# Expected curl result:
# Data logged to your console

# Log result:
# { userId: 1,
# id: 1,
# title: 'delectus aut autem',
# completed: false }
```

Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))

```bash
Expand Down
4 changes: 4 additions & 0 deletions examples/socket.io-chat-app/README.md
Expand Up @@ -19,6 +19,10 @@ npm install
npm run start
```

Test it:

Open http://localhost:4000 in your browser.

Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))

```bash
Expand Down
6 changes: 3 additions & 3 deletions examples/socket.io-chat-app/index.js
@@ -1,13 +1,13 @@
const micro = require('micro');
const { micro } = require('micro');
const fs = require('fs');
const path = require('path');

const document = path.join(__dirname, 'index.html');
const html = fs.readFileSync(document);

const server = micro(async (req, res) => {
const server = micro(() => {
console.log('Serving index.html');
res.end(html);
return html.toString();
});

const io = require('socket.io')(server);
Expand Down
2 changes: 1 addition & 1 deletion examples/socket.io-chat-app/package.json
Expand Up @@ -9,6 +9,6 @@
"license": "ISC",
"dependencies": {
"micro": "latest",
"socket.io": "1.7.3"
"socket.io": "2.2.0"
}
}
14 changes: 14 additions & 0 deletions examples/urlencoded-body-parsing/README.md
Expand Up @@ -17,6 +17,20 @@ npm install
npm run start
```

Test it:

```bash
curl --request GET \
--url http://localhost:3000/ \
--data 'name=micro&type=awesome'

# Expected curl result:
# Data logged to your console

# Log result:
# { name: 'micro', type: 'awesome' }
```

Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))

```bash
Expand Down
9 changes: 9 additions & 0 deletions examples/with-graphql-request/README.md
Expand Up @@ -16,6 +16,15 @@ $ yarn install # (or `$ npm install`)
$ yarn run start # (or `$ npm run start`)
```

Test it:
```bash
curl --request GET \
--url 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"}]}
```

Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))

```bash
Expand Down
8 changes: 8 additions & 0 deletions examples/with-https/README.md
Expand Up @@ -16,6 +16,14 @@ npm install
npm run start
```

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

# Expected curl result:
# {"encrypted":true}
```

Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))

```bash
Expand Down
14 changes: 7 additions & 7 deletions examples/with-https/index.js
@@ -1,17 +1,17 @@
const https = require('https');
const {run, send} = require('micro');
const { listener, res } = require('micro');

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

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

const options = {key, cert, passphrase};
const options = { key, cert, passphrase };

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

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

const server = microHttps(handler);

server.listen(PORT);
console.log(`Listening on https://localhost:${PORT}`);

0 comments on commit 68411e5

Please sign in to comment.