当前位置:网站首页>[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 :
边栏推荐
- .elf .map .list .hex文件
- @The difference between Autowired and @resource
- Stm32f1+bc20+mqtt+freertos system is connected to Alibaba cloud to transmit temperature and humidity and control LED lights
- RT thread API reference manual
- 如何给Arduino项目添加音乐播放功能
- Talking about the startup of Oracle Database
- Classification, understanding and application of common methods of JS array
- ORA-02030: can only select from fixed tables/views
- Redis 缓存更新策略,缓存穿透、雪崩、击穿问题
- ARM PC=PC+8 最便于理解的阐述
猜你喜欢
Fashion-Gen: The Generative Fashion Dataset and Challenge 论文解读&数据集介绍
js 变量作用域和函数的学习笔记
基于Redis的分布式ID生成器
MP3mini播放模块arduino<DFRobotDFPlayerMini.h>函数详解
数据库课程设计:高校教务管理系统(含代码)
(三)R语言的生物信息学入门——Function, data.frame, 简单DNA读取与分析
程序员老鸟都会搞错的问题 C语言基础 指针和数组
ORA-02030: can only select from fixed tables/views
Pat 1097 duplication on a linked list (25 points)
ARM PC=PC+8 最便于理解的阐述
随机推荐
Arduino get random number
ESP8266通过arduino IED连接巴法云(TCP创客云)
Pytorch: tensor operation (I) contiguous
Comparison of solutions of Qualcomm & MTK & Kirin mobile platform USB3.0
open-mmlab labelImg mmdetection
E-commerce data analysis -- salary prediction (linear regression)
Cannot change version of project facet Dynamic Web Module to 2.3.
Remember an experience of ECS being blown up by passwords - closing a small black house, changing passwords, and changing ports
Reno7 60W super flash charging architecture
Oppo vooc fast charging circuit and protocol
Selective sorting and bubble sorting [C language]
Common DOS commands
History object
Arduino uno R3 register writing method (1) -- pin level state change
MP3mini播放模块arduino<DFRobotDFPlayerMini.h>函数详解
MySQL時間、時區、自動填充0的問題
@Autowired 和 @Resource 的区别
Important methods of array and string
AMBA、AHB、APB、AXI的理解
MySQL time, time zone, auto fill 0