docs: apply Date.now()
to all docs (#988)
This commit is contained in:
parent
302814e7a3
commit
08eb1a20c3
4 changed files with 12 additions and 12 deletions
|
@ -70,9 +70,9 @@ app.use(async (ctx, next) => {
|
|||
// next is a function that is invoked to execute the downstream middleware. It returns a Promise with a then function for running code after completion.
|
||||
|
||||
app.use((ctx, next) => {
|
||||
const start = new Date();
|
||||
const start = Date.now();
|
||||
return next().then(() => {
|
||||
const ms = new Date() - start;
|
||||
const ms = Date.now() - start;
|
||||
console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -81,18 +81,18 @@ const app = new Koa();
|
|||
// x-response-time
|
||||
|
||||
app.use(async function (ctx, next) {
|
||||
const start = new Date();
|
||||
const start = Date.now();
|
||||
await next();
|
||||
const ms = new Date() - start;
|
||||
const ms = Date.now() - start;
|
||||
ctx.set('X-Response-Time', `${ms}ms`);
|
||||
});
|
||||
|
||||
// logger
|
||||
|
||||
app.use(async function (ctx, next) {
|
||||
const start = new Date();
|
||||
const start = Date.now();
|
||||
await next();
|
||||
const ms = new Date() - start;
|
||||
const ms = Date.now() - start;
|
||||
console.log(`${ctx.method} ${ctx.url} - ${ms}`);
|
||||
});
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
|
||||
```js
|
||||
async function responseTime(ctx, next) {
|
||||
const start = new Date();
|
||||
const start = Date.now();
|
||||
await next();
|
||||
const ms = new Date() - start;
|
||||
const ms = Date.now() - start;
|
||||
ctx.set('X-Response-Time', `${ms}ms`);
|
||||
}
|
||||
|
||||
|
|
|
@ -39,9 +39,9 @@ It is however recommended that you choose to migrate all v1.x middleware as soon
|
|||
```js
|
||||
// Koa will convert
|
||||
app.use(function *(next) {
|
||||
const start = new Date();
|
||||
const start = Date.now();
|
||||
yield next;
|
||||
const ms = new Date() - start;
|
||||
const ms = Date.now() - start;
|
||||
console.log(`${this.method} ${this.url} - ${ms}ms`);
|
||||
});
|
||||
```
|
||||
|
@ -52,9 +52,9 @@ You could do it manually as well, in which case Koa will not convert.
|
|||
const convert = require('koa-convert');
|
||||
|
||||
app.use(convert(function *(next) {
|
||||
const start = new Date();
|
||||
const start = Date.now();
|
||||
yield next;
|
||||
const ms = new Date() - start;
|
||||
const ms = Date.now() - start;
|
||||
console.log(`${this.method} ${this.url} - ${ms}ms`);
|
||||
}));
|
||||
```
|
||||
|
|
Loading…
Reference in a new issue