当前位置:网站首页>Egg framework usage (2)
Egg framework usage (2)
2022-08-05 09:32:00 【The front small grass seed】
Table of Contents
The relationship between the static resources and routing of the egg framework
router router
There is a device in life called a router: the user sends the request data to the router, and the router connects to different servers according to the user's needs.
Routing: Refers to different URLs to execute different branches or programs.
router.get('/ajax1',controller.user.ajax1); //Register routingAnalysis: The user sends the requested URL /ajax1 to the router, and the router executes its corresponding program controller.user.ajax1 according to the URL requested by the user, and then returns the corresponding result.
egg frameThe relationship between static resources and routing
1. When the user enters the URL, check the static hosting directory (public folder) for the required resources, read the static file and send it to the user, if notJust go to the router.js folder to see if there is a matching registration URL, call the corresponding function to execute, if not, return 404 Not Found
Note: When registering a route, the route name should not conflict with the static file name, otherwise the static resources will be preferentially accessed.
2. When the registered routes have the same, only the first one will be matched, and the following ones will not be matched again:
Analysis: When the user enters ip:port/ajax1, only the first /ajax1 will be matched and then controller.user.ajax1 will be executed, which is equivalent to res.end(), and a request will only run once.
3. router.get('/*',controller.home.all); The meaning of this code is:
router.get('/*',controller.home.all);Analysis: '/*' means any URL entered by the browser can be matched
If:
//The code order is like this:router.get("/*",controller.home.all);router.get('/', controller.home.index);router.get('/ajax1',controller.user.ajax1); async all() {this.ctx.body = 'return a front-end interface' //return to the front-end}Enter the URL in the browser: 127.0.0.1:7001/ajax1 to visitCan't reach /ajax1 because '/*' is accessed
Summary: When routing network requests in egg, the processing properties of the backend: static files > route matching (matching in order)
'/*' signal routing means all URLs match
边栏推荐
- 深度学习21天——卷积神经网络(CNN):服装图像分类(第3天)
- 开源一夏|OpenHarmony如何查询设备类型(eTS)
- Creo 9.0 基准特征:基准平面
- 【零基础玩转BLDC系列】无刷直流电机无位置传感器三段式启动法详细介绍及代码分享
- Keil升级到AC6后,到底有哪些变化?
- 2.4G无线收发模块的应用
- eKuiper Newsletter 2022-07|v1.6.0:Flow 编排 + 更好用的 SQL,轻松表达业务逻辑
- Which big guy has the 11G GI and ojvm patches in April or January 2020, please help?
- 无题十三
- 正则表达式replaceFirst()方法具有什么功能呢?
猜你喜欢
随机推荐
Advanced usage of C language
CVPR 2022 | 将X光图片用于垃圾分割,港中大(深圳)探索大规模智能垃圾分类
【Excel实战】--图表联动demo_001
无题七
科普大佬说 | 港大黄凯斌老师带你解锁黑客帝国与6G的关系
汇编语言(8)x86内联汇编
EU | Horizon 2020 ENSEMBLE: D2.13 SOTIF Safety Concept (Part 2)
Hundred lines of code launch red hearts, why programmers lose their girlfriends!
Neuron Newsletter 2022-07|新增非 A11 驱动、即将支持 OPC DA
七夕浪漫约会不加班,RPA机器人帮你搞定工作
营销建议 | 您有一份八月营销月历待查收! 建议收藏 !
2022-08-01 Review the basic binary tree and operations
Does flink cdc support synchronization from oracle dg library?
Creo 9.0 基准特征:基准平面
PAT Level B - B1021 Single Digit Statistics (15)
tensorflow.keras无法引入layers
egg框架使用(一)
Is there a problem with writing this?How to synchronize data in sql-client
请问大佬们 ,使用 Flink SQL CDC 是不是做不到两个数据库的实时同步啊
Oracle临时表空间作用









