当前位置:网站首页>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 routing
Analysis: 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
边栏推荐
- CCVR eases heterogeneous federated learning based on classifier calibration
- 正则表达式replaceFirst()方法具有什么功能呢?
- 七夕浪漫约会不加班,RPA机器人帮你搞定工作
- 欧盟 | 地平线 2020 ENSEMBLE:D2.13 SOTIF Safety Concept(上)
- egg框架使用(一)
- ffmpeg drawtext add text watermark
- Qiu Jun, CEO of Eggplant Technology: Focus on users and make products that users really need
- 线程之Happens-before规则
- 请问如果想往mysql里面写数据,直接用flink-connector-jdbc就可以吧,可是我在f
- 21 Days of Deep Learning - Convolutional Neural Networks (CNN): Weather Recognition (Day 5)
猜你喜欢
施一公:科学需要想象,想象来自阅读
并发之CAS
哪位大佬有20年4月或者1月的11G GI和ojvm补丁呀,帮忙发下?
5.部署web项目到云服务器
Keil升级到AC6后,到底有哪些变化?
使用HBuilder离线本地打包ipa教程
Tanabata romantic date without overtime, RPA robot helps you get the job done
Redis源码解析:Redis Cluster
Analysis and practice of antjian webshell dynamic encrypted connection
为什么我推荐使用智能化async?
随机推荐
Overall design and implementation of Kubernetes-based microservice project
21 Days of Deep Learning - Convolutional Neural Networks (CNN): Weather Recognition (Day 5)
无题二
Creo 9.0 基准特征:基准点
今天是元宵节~~
Bias lock/light lock/heavy lock lock is healthier. How is locking and unlocking accomplished?
欧盟 | 地平线 2020 ENSEMBLE:D2.13 SOTIF Safety Concept(上)
mysql进阶(二十七)数据库索引原理
周报2022-8-4
歌词整理
PAT乙级-B1019 数字黑洞(20)
Excuse me if you want to write data in mysql, with flink - connector - JDBC directly is ok, but I'm in the f
sql server中 两表查询 平均数 分组
What is the function of the regular expression replaceAll() method?
线程之Happens-before规则
【零基础玩转BLDC系列】无刷直流电机无位置传感器三段式启动法详细介绍及代码分享
leetcode: 529. 扫雷游戏
openpyxl to manipulate Excel files
XCODE12 在使用模拟器(SIMULATOR)时编译错误的解决方法
仿SBUS与串口数据固定转换