当前位置:网站首页>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
边栏推荐
- PAT Grade B-B1020 Mooncake(25)
- PAT Level B - B1021 Single Digit Statistics (15)
- 明天去订票,准备回家咯~~
- HStreamDB Newsletter 2022-07|分区模型优化、数据集成框架进一步完善
- ffmpeg drawtext add text watermark
- 21 Days of Deep Learning - Convolutional Neural Networks (CNN): Weather Recognition (Day 5)
- Dry goods!Generative Model Evaluation and Diagnosis
- leetcode refers to Offer 10- II. Frog jumping steps
- 程序员的七种武器
- IO流篇 -- 基于io流实现文件夹拷贝(拷贝子文件夹及子文件夹内文件)满满的干货
猜你喜欢
egg框架使用(二)
使用稀疏 4D 卷积对 3D LiDAR 数据中的运动对象进行后退分割(IROS 2022)
seata源码解析:TM RM 客户端的初始化过程
科普大佬说 | 港大黄凯斌老师带你解锁黑客帝国与6G的关系
eKuiper Newsletter 2022-07|v1.6.0:Flow 编排 + 更好用的 SQL,轻松表达业务逻辑
自定义过滤器和拦截器实现ThreadLocal线程封闭
dotnet OpenXML parsing PPT charts Getting started with area charts
手把手教你纯c实现异常捕获try-catch组件
茄子科技CEO仇俊:以用户为中心,做用户真正需要的产品
After Keil upgrades to AC6, what changes?
随机推荐
Pytorch Deep Learning Quick Start Tutorial -- Mound Tutorial Notes (3)
Which big guy has the 11G GI and ojvm patches in April or January 2020, please help?
无题五
(转)[Json]net.sf.json 和org.json 的差别及用法
my journal link
七夕浪漫约会不加班,RPA机器人帮你搞定工作
CVPR 2022 | 将X光图片用于垃圾分割,港中大(深圳)探索大规模智能垃圾分类
PAT Grade B-B1020 Mooncake(25)
2022-08-01 回顾基础二叉树以及操作
flink cdc支持从oracle dg库同步吗
Going to book tickets tomorrow, ready to go home~~
leetcode: 529. Minesweeper Game
长达四年的减肥记录
2022-08-01 Review the basic binary tree and operations
egg框架使用(二)
基于 Kubernetes 的微服务项目整体设计与实现
这样写有问题吗?怎么在sql-client 是可以做到数据的同步的
XCODE12 在使用模拟器(SIMULATOR)时编译错误的解决方法
Two-table query average grouping in sql server
Tanabata romantic date without overtime, RPA robot helps you get the job done