当前位置:网站首页>[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 :


边栏推荐
- Kaggle competition two Sigma connect: rental listing inquiries (xgboost)
- Esp8266 connect onenet (old mqtt mode)
- Esp8266 connects to bafayun (TCP maker cloud) through Arduino IED
- gcc 编译选项
- @Autowired 和 @Resource 的区别
- 如何给Arduino项目添加音乐播放功能
- Cannot change version of project facet Dynamic Web Module to 2.3.
- Gateway 根据服务名路由失败,报错 Service Unavailable, status=503
- [899]有序队列
- JS變量類型以及常用類型轉換
猜你喜欢

JS function promotion and declaration promotion of VaR variable

Analysis of charging architecture of glory magic 3pro

(四)R语言的数据可视化——矩阵图、柱状图、饼图、散点图与线性回归、带状图

Kconfig Kbuild

JS 函数提升和var变量的声明提升

Page performance optimization of video scene
![[golang] leetcode intermediate - fill in the next right node pointer of each node & the k-smallest element in the binary search tree](/img/6e/0802a92511ac50a652afa1678ad28c.jpg)
[golang] leetcode intermediate - fill in the next right node pointer of each node & the k-smallest element in the binary search tree

Amba, ahb, APB, Axi Understanding

Générateur d'identification distribué basé sur redis

基于Redis的分布式ID生成器
随机推荐
[offer9]用两个栈实现队列
Imgcat usage experience
高通&MTK&麒麟 手機平臺USB3.0方案對比
Dead loop in FreeRTOS task function
[899]有序队列
Esp8266 connects to onenet cloud platform (mqtt) through Arduino IDE
Who says that PT online schema change does not lock the table, or deadlock
The dolphin scheduler remotely executes shell scripts through the expect command
Feature of sklearn_ extraction. text. CountVectorizer / TfidVectorizer
ESP8266通过arduino IED连接巴法云(TCP创客云)
單片機藍牙無線燒錄
2022.2.12 resumption
ES6语法总结--下篇(进阶篇 ES6~ES11)
嵌入式启动流程
[Offer29] 排序的循环链表
Arm pc=pc+8 is the most understandable explanation
Talking about the startup of Oracle Database
Understanding of AMBA, AHB, APB and Axi
[esp32 learning-2] esp32 address mapping
ESP learning problem record