当前位置:网站首页>[Nodejs] 20. Koa2 onion ring model ----- code demonstration
[Nodejs] 20. Koa2 onion ring model ----- code demonstration
2022-07-06 12:22:00 【weiweicn!】
notes : Demo official website (https://koa.bootcss.com/) The code in
- The code is as follows :
// demonstration koa2 Onion ring model of middleware
const Koa = require('koa');
const app = new Koa;
// logger ctx = req+res
app.use(async(ctx, next) => {
await next(); // Execute next Middleware
const rt = ctx.response.get('X-Response-Time') // res Get time difference
console.log(`${
ctx.method} ${
ctx.url} - ${
rt}`)
})
// x-response-time
app.use(async(ctx, next) => {
const start = Date.now();
await next(); // Execute next Middleware
const ms = Date.now()- start; // Calculate the time difference
ctx.set('X-Response-Time', `${
ms}ms`) // Record / Set the time difference
})
// response
app.use(async(ctx, next) => {
ctx.body = 'Hello world';
})
app.listen(3000);
console.log('koa2 Has started listening 3000 port ')
- Enter access in browser :
边栏推荐
- Pytoch temperature prediction
- JS變量類型以及常用類型轉換
- History object
- Symbolic representation of functions in deep learning papers
- RuntimeError: cuDNN error: CUDNN_STATUS_NOT_INITIALIZED
- 编译原理:源程序的预处理及词法分析程序的设计与实现(含代码)
- Pytoch implements simple linear regression demo
- ESP学习问题记录
- Arduino gets the length of the array
- MySQL时间、时区、自动填充0的问题
猜你喜欢
Redis 缓存更新策略,缓存穿透、雪崩、击穿问题
Pytorch: tensor operation (I) contiguous
RT thread API reference manual
Working principle of genius telephone watch Z3
Comparaison des solutions pour la plate - forme mobile Qualcomm & MTK & Kirin USB 3.0
STM32 how to locate the code segment that causes hard fault
Remember an experience of ECS being blown up by passwords - closing a small black house, changing passwords, and changing ports
I2C bus timing explanation
C language callback function [C language]
JS variable types and common type conversions
随机推荐
History object
ES6 grammar summary -- Part I (basic)
Redis based distributed locks and ultra detailed improvement ideas
Selective sorting and bubble sorting [C language]
Pytoch implements simple linear regression demo
RT thread API reference manual
. elf . map . list . Hex file
Problèmes avec MySQL time, fuseau horaire, remplissage automatique 0
[offer9]用两个栈实现队列
JS變量類型以及常用類型轉換
Postman 中级使用教程【环境变量、测试脚本、断言、接口文档等】
高通&MTK&麒麟 手機平臺USB3.0方案對比
CUDA C programming authoritative guide Grossman Chapter 4 global memory
Kaggle competition two Sigma connect: rental listing inquiries (xgboost)
Minio文件下载问题——inputstream:closed
Bubble sort [C language]
Intermediate use tutorial of postman [environment variables, test scripts, assertions, interface documents, etc.]
Working principle of genius telephone watch Z3
程序设计大作业:教务管理系统(C语言)
(三)R语言的生物信息学入门——Function, data.frame, 简单DNA读取与分析