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.
|
// 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) => {
|
app.use((ctx, next) => {
|
||||||
const start = new Date();
|
const start = Date.now();
|
||||||
return next().then(() => {
|
return next().then(() => {
|
||||||
const ms = new Date() - start;
|
const ms = Date.now() - start;
|
||||||
console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);
|
console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -81,18 +81,18 @@ const app = new Koa();
|
||||||
// x-response-time
|
// x-response-time
|
||||||
|
|
||||||
app.use(async function (ctx, next) {
|
app.use(async function (ctx, next) {
|
||||||
const start = new Date();
|
const start = Date.now();
|
||||||
await next();
|
await next();
|
||||||
const ms = new Date() - start;
|
const ms = Date.now() - start;
|
||||||
ctx.set('X-Response-Time', `${ms}ms`);
|
ctx.set('X-Response-Time', `${ms}ms`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// logger
|
// logger
|
||||||
|
|
||||||
app.use(async function (ctx, next) {
|
app.use(async function (ctx, next) {
|
||||||
const start = new Date();
|
const start = Date.now();
|
||||||
await next();
|
await next();
|
||||||
const ms = new Date() - start;
|
const ms = Date.now() - start;
|
||||||
console.log(`${ctx.method} ${ctx.url} - ${ms}`);
|
console.log(`${ctx.method} ${ctx.url} - ${ms}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -13,9 +13,9 @@
|
||||||
|
|
||||||
```js
|
```js
|
||||||
async function responseTime(ctx, next) {
|
async function responseTime(ctx, next) {
|
||||||
const start = new Date();
|
const start = Date.now();
|
||||||
await next();
|
await next();
|
||||||
const ms = new Date() - start;
|
const ms = Date.now() - start;
|
||||||
ctx.set('X-Response-Time', `${ms}ms`);
|
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
|
```js
|
||||||
// Koa will convert
|
// Koa will convert
|
||||||
app.use(function *(next) {
|
app.use(function *(next) {
|
||||||
const start = new Date();
|
const start = Date.now();
|
||||||
yield next;
|
yield next;
|
||||||
const ms = new Date() - start;
|
const ms = Date.now() - start;
|
||||||
console.log(`${this.method} ${this.url} - ${ms}ms`);
|
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');
|
const convert = require('koa-convert');
|
||||||
|
|
||||||
app.use(convert(function *(next) {
|
app.use(convert(function *(next) {
|
||||||
const start = new Date();
|
const start = Date.now();
|
||||||
yield next;
|
yield next;
|
||||||
const ms = new Date() - start;
|
const ms = Date.now() - start;
|
||||||
console.log(`${this.method} ${this.url} - ${ms}ms`);
|
console.log(`${this.method} ${this.url} - ${ms}ms`);
|
||||||
}));
|
}));
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in a new issue