当前位置:网站首页>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
边栏推荐
猜你喜欢

Science bosses say | Hong Kong rhubarb KaiBin teacher take you unlock the relationship between the matrix and 6 g

Analysis and practice of antjian webshell dynamic encrypted connection

Seata source code analysis: initialization process of TM RM client

汇编语言(8)x86内联汇编

Marketing Suggestions | You have an August marketing calendar to check! Suggest a collection!

手把手教你纯c实现异常捕获try-catch组件

Undefined symbols for architecture arm64解决方案

轩辕实验室丨欧盟EVITA项目预研 第一章(四)

CPU的亲缘性affinity

The technological achievements of Shanghai Konan were selected into the "2021 Shanghai Network Security Industry Innovation Research Achievement Catalog" by the Municipal Commission of Economy and Inf
随机推荐
Dry goods!Generative Model Evaluation and Diagnosis
openpyxl to manipulate Excel files
Pytorch Deep Learning Quick Start Tutorial -- Mound Tutorial Notes (3)
Advanced usage of C language
2022-08-01 回顾基础二叉树以及操作
The technological achievements of Shanghai Konan were selected into the "2021 Shanghai Network Security Industry Innovation Research Achievement Catalog" by the Municipal Commission of Economy and Inf
C语言的高级用法
Concurrent CAS
CCVR基于分类器校准缓解异构联邦学习
轩辕实验室丨欧盟EVITA项目预研 第一章(四)
(转)[Json]net.sf.json 和org.json 的差别及用法
XCODE12 在使用模拟器(SIMULATOR)时编译错误的解决方法
seata源码解析:事务状态及全局锁的存储
无题十二
IDEA执行Test操作导致数据插入时出现了重复数据
HStreamDB Newsletter 2022-07|分区模型优化、数据集成框架进一步完善
leetcode: 529. 扫雷游戏
无题十一
Hbuilder 学习使用中的一些记录
After Keil upgrades to AC6, what changes?