当前位置:网站首页>Koa koa-combine-routers 分路由管理
Koa koa-combine-routers 分路由管理
2022-07-01 00:37:00 【前端猫】
安装:npm install koa koa-router koa-body @koa/cors koa-json -S
npm install koa-combine-routers -S // 管理路由
koa-combine-routers - npm // 查看源代码
第一步:初始化package.js npm init -y
第二步:npm install koa koa-router koa-body @koa/cors koa-json -S
npm install koa-combine-routers -S // 管理路由
第三步:目录
在api的a.js
function a (ctx){
ctx.body = {
"messgae":"a"
}
}
module.exports = {
a
}在api的b.js
function a (ctx){
ctx.body = {
"messgae":"b"
}
}
module.exports = {
b
}
routes文件的aRouter.js
const KoaRouter = require('koa-router')
const a = require("../api/a.js")
const router = new KoaRouter()
router.get('/a',a)
module.exports = router
routes文件的bRouter.js
const KoaRouter = require('koa-router')
const b = require("../api/b")
const router = new KoaRouter()
router.get('/b',b)
module.exports = router合并路由
const combineRoutes = require('koa-combine-routers')
const aRouters = require("./aRouter")
const bRouters = require("./bRouter")
module.exports = combineRoutes (
aRouters,
bRouters
)
src文件下的index.js
// 入口文件
const koa = require('koa')
const app = new koa()
const router = require('./routes/routes')
app.use(router())
app.listen(3000)边栏推荐
- C # generates PPK files in putty format (supports passphrase)
- 优质的水泵 SolidWorks模型素材推荐,不容错过
- Tcp/ip protocol stack, about TCP_ RST | TCP_ ACK correct attitude
- 2022-2028 global rotary transmission system industry research and trend analysis report
- Self examination before school starts
- What should I do without 50W bride price
- Teach you how to use Hal library to get started -- become a lighting master
- CTF tool (1) -- archpr -- including installation / use process
- Deployment of mini version message queue based on redis6.0
- Luogu p1144 shortest circuit count
猜你喜欢

Oracle临时表详解

Oracle temporary table explanation

Error 2059 when Navicat connects to MySQL

Redis - understand the master-slave replication mechanism

CTF tool (1) -- archpr -- including installation / use process

优质的水泵 SolidWorks模型素材推荐,不容错过

2022-2028 global single travel industry research and trend analysis report

20220215 misc buctf easycap Wireshark tracks TCP flow hidden key (use of WinHex tool)

left join左连接匹配数据为NULL时显示指定值

2022-2028 global capsule shell industry research and trend analysis report
随机推荐
魔王冷饭||#101 魔王解惑数量多与质量;员工管理;高考志愿填报;游戏架构设计
The quantity and quality of the devil's cold rice 101; Employee management; College entrance examination voluntary filling; Game architecture design
Basic data structure of redis
2022-2028 global ultra high purity electrolytic iron powder industry research and trend analysis report
A letter to 5000 fans!
Two-stage RO: part 1
Oracle data integrity
【原创】 PLSQL 索引排序优化
2022-2028 global public address fire alarm system industry research and trend analysis report
Tibetan poem PTA
2022就要过去一半了,挣钱好难
优质的水泵 SolidWorks模型素材推荐,不容错过
2022-2028 global PTFE lined valve industry research and trend analysis report
Vnctf 2022 cm CM1 re reproduction
What if the disk of datanode is full?
Solving the weird problem that the query conditions affect the value of query fields in MySQL query
20220216 misc buuctf another world WinHex, ASCII conversion flag zip file extraction and repair if you give me three days of brightness zip to rar, Morse code waveform conversion mysterious tornado br
PHP online confusion encryption tutorial sharing + basically no solution
What is product thinking
The principle and related problems of acid in MySQL
