当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
openpyxl to manipulate Excel files
Happens-before rules for threads
手把手教你纯c实现异常捕获try-catch组件
15.1.1、md—md的基础语法,快速的写文本备忘录
Pytorch深度学习快速入门教程 -- 土堆教程笔记(三)
无题三
无题十三
sql server中 两表查询 平均数 分组
HStreamDB Newsletter 2022-07|分区模型优化、数据集成框架进一步完善
营销建议 | 您有一份八月营销月历待查收! 建议收藏 !
无题九
干货!生成模型的评价与诊断
使用稀疏 4D 卷积对 3D LiDAR 数据中的运动对象进行后退分割(IROS 2022)
seata源码解析:事务状态及全局锁的存储
百行代码发射红心,程序员何愁命不中女朋友!
seata源码解析:TM RM 客户端的初始化过程
Xcode10的打包方式distribute app和启动项目报错以及Xcode 打包本地ipa包安装到手机上
哪位大佬有20年4月或者1月的11G GI和ojvm补丁呀,帮忙发下?
2022-08-01 Review the basic binary tree and operations
Concurrent CAS









