Browse Source

Simplify readme example with top level await

master
Luke Childs 6 years ago
parent
commit
3d79890f4d
  1. 29
      README.md

29
README.md

@ -26,24 +26,23 @@ npm install --save-dev create-test-server
```js
const createTestServer = require('create-test-server');
createTestServer().then(server => {
console.log(server.url);
// http://localhost:5486
console.log(server.sslUrl);
// https://localhost:5487
// This is just an Express route
// You could use any Express middleware too
server.get('/foo', (req, res) => {
const server = await createTestServer();
console.log(server.url);
// http://localhost:5486
console.log(server.sslUrl);
// https://localhost:5487
// This is just an Express route
// You could use any Express middleware too
server.get('/foo', (req, res) => {
res.send('bar');
});
});
// You can return a body directly too
server.get('/foo', () => 'bar');
server.get('/foo', 'bar');
// You can return a body directly too
server.get('/foo', () => 'bar');
server.get('/foo', 'bar');
// server.url + '/foo' and server.sslUrl + '/foo' will respond with 'bar'
});
// server.url + '/foo' and server.sslUrl + '/foo' will respond with 'bar'
```
The following `Content-Type` headers will be parsed and exposed via `req.body`:

Loading…
Cancel
Save